本文整理汇总了C#中KeyPressEventArgs.GetKeyChar方法的典型用法代码示例。如果您正苦于以下问题:C# KeyPressEventArgs.GetKeyChar方法的具体用法?C# KeyPressEventArgs.GetKeyChar怎么用?C# KeyPressEventArgs.GetKeyChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyPressEventArgs
的用法示例。
在下文中一共展示了KeyPressEventArgs.GetKeyChar方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KeyPress
void KeyPress(KeyPressEventArgs e)
{
for (int i = 0; i < WidgetCount; i++)
{
MenuWidget w = widgets[i];
if (w != null)
{
if (w.type == WidgetType.Textbox)
{
if (w.editing)
{
string s = CharToString(e.GetKeyChar());
if (e.GetKeyChar() == 8) // backspace
{
if (StringTools.StringLength(game.platform, w.text) > 0)
{
w.text = StringTools.StringSubstring(game.platform, w.text, 0, StringTools.StringLength(game.platform, w.text) - 1);
}
return;
}
if (e.GetKeyChar() == 9 || e.GetKeyChar() == 13) // tab, enter
{
return;
}
if (e.GetKeyChar() == 22) //paste
{
if (game.platform.ClipboardContainsText())
{
w.text = StringTools.StringAppend(game.platform, w.text, game.platform.ClipboardGetText());
}
return;
}
if (game.platform.IsValidTypingChar(e.GetKeyChar()))
{
w.text = StringTools.StringAppend(game.platform, w.text, s);
}
}
}
}
}
}
示例2: HandleKeyPress
public void HandleKeyPress(KeyPressEventArgs e)
{
if (e.GetKeyChar() == 70 || e.GetKeyChar() == 102) // 'F', 'f'
{
filter += 1;
if (filter == 3)
{
filter = 0;
}
}
if (e.GetKeyChar() == 96) // '`'
{
screen.OnBackPressed();
}
screen.OnKeyPress(e);
}
示例3: KeyPress
void KeyPress(KeyPressEventArgs e)
{
for (int i = 0; i < WidgetCount; i++)
{
MenuWidget w = widgets[i];
if (w != null)
{
if (w.type == WidgetType.Textbox)
{
if (w.editing)
{
if (menu.p.IsValidTypingChar(e.GetKeyChar()))
{
w.text = StringTools.StringAppend(menu.p, w.text, menu.CharToString(e.GetKeyChar()));
}
}
}
}
}
}
示例4: OnKeyPress
public override void OnKeyPress(Game game_, KeyPressEventArgs args)
{
if (game.guistate != GuiState.Inventory)
{
return;
}
int keyChar = args.GetKeyChar();
if (keyChar == 49) { game.ActiveMaterial = 0; }
if (keyChar == 50) { game.ActiveMaterial = 1; }
if (keyChar == 51) { game.ActiveMaterial = 2; }
if (keyChar == 52) { game.ActiveMaterial = 3; }
if (keyChar == 53) { game.ActiveMaterial = 4; }
if (keyChar == 54) { game.ActiveMaterial = 5; }
if (keyChar == 55) { game.ActiveMaterial = 6; }
if (keyChar == 56) { game.ActiveMaterial = 7; }
if (keyChar == 57) { game.ActiveMaterial = 8; }
if (keyChar == 48) { game.ActiveMaterial = 9; }
}
示例5: OnKeyPress
public override void OnKeyPress(Game game_, KeyPressEventArgs args)
{
if (game.guistate != GuiState.Normal)
{
//Don't open chat when not in normal game
return;
}
int eKeyChar = args.GetKeyChar();
int chart = 116;
int charT = 84;
int chary = 121;
int charY = 89;
if ((eKeyChar == chart || eKeyChar == charT) && game.GuiTyping == TypingState.None)
{
game.GuiTyping = TypingState.Typing;
game.GuiTypingBuffer = "";
game.IsTeamchat = false;
return;
}
if ((eKeyChar == chary || eKeyChar == charY) && game.GuiTyping == TypingState.None)
{
game.GuiTyping = TypingState.Typing;
game.GuiTypingBuffer = "";
game.IsTeamchat = true;
return;
}
if (game.GuiTyping == TypingState.Typing)
{
int c = eKeyChar;
if (game.platform.IsValidTypingChar(c))
{
game.GuiTypingBuffer = StringTools.StringAppend(game.platform, game.GuiTypingBuffer, game.CharToString(c));
}
int charTab = 9;
//Handles player name autocomplete in chat
if (c == charTab && game.platform.StringTrim(game.GuiTypingBuffer) != "")
{
for (int i = 0; i < game.entitiesCount; i++)
{
Entity entity = game.entities[i];
if (entity == null) { continue; }
if (entity.drawName == null) { continue; }
if (!entity.drawName.ClientAutoComplete) { continue; }
DrawName p = entity.drawName;
//Use substring here because player names are internally in format &xNAME (so we need to cut first 2 characters)
if (game.platform.StringStartsWithIgnoreCase(StringTools.StringSubstringToEnd(game.platform, p.Name, 2), game.GuiTypingBuffer))
{
game.GuiTypingBuffer = StringTools.StringAppend(game.platform, StringTools.StringSubstringToEnd(game.platform, p.Name, 2), ": ");
break;
}
}
}
}
}
示例6: OnKeyPress
public override void OnKeyPress(Game game, KeyPressEventArgs args)
{
if (game.guistate != GuiState.ModalDialog
&& game.guistate != GuiState.Normal)
{
return;
}
for (int i = 0; i < game.dialogsCount; i++)
{
if (game.dialogs[i] == null) { continue; }
game.dialogs[i].screen.OnKeyPress(game, args);
}
for (int k = 0; k < game.dialogsCount; k++)
{
if (game.dialogs[k] == null)
{
continue;
}
VisibleDialog d = game.dialogs[k];
for (int i = 0; i < d.value.WidgetsCount; i++)
{
Packet_Widget w = d.value.Widgets[i];
if (w == null)
{
continue;
}
// Only typeable characters are handled by KeyPress (for special characters use KeyDown)
string valid = "abcdefghijklmnopqrstuvwxyz1234567890\t ";
if (game.platform.StringContains(valid, game.CharToString(w.ClickKey)))
{
if (args.GetKeyChar() == w.ClickKey)
{
game.SendPacketClient(ClientPackets.DialogClick(w.Id, new string[0], 0));
return;
}
}
}
}
}
示例7: OnKeyPress
public override void OnKeyPress(Game game_, KeyPressEventArgs args)
{
if (game.guistate != GuiState.Normal)
{
//Don't open chat when not in normal game
return;
}
int eKeyChar = args.GetKeyChar();
int chart = 116;
int charT = 84;
int chary = 121;
int charY = 89;
if ((eKeyChar == chart || eKeyChar == charT) && game.GuiTyping == TypingState.None)
{
game.GuiTyping = TypingState.Typing;
game.GuiTypingBuffer = "";
game.IsTeamchat = false;
return;
}
if ((eKeyChar == chary || eKeyChar == charY) && game.GuiTyping == TypingState.None)
{
game.GuiTyping = TypingState.Typing;
game.GuiTypingBuffer = "";
game.IsTeamchat = true;
return;
}
if (game.GuiTyping == TypingState.Typing)
{
int c = eKeyChar;
if (game.platform.IsValidTypingChar(c))
{
game.GuiTypingBuffer = StringTools.StringAppend(game.platform, game.GuiTypingBuffer, game.CharToString(c));
}
}
}
示例8: OnKeyPress
public override void OnKeyPress(Game game_, KeyPressEventArgs args)
{
if (game.guistate != GuiState.Normal)
{
//Don't open chat when not in normal game
return;
}
int eKeyChar = args.GetKeyChar();
int chart = 116;
int charT = 84;
int chary = 121;
int charY = 89;
if ((eKeyChar == chart || eKeyChar == charT) && game.GuiTyping == TypingState.None)
{
game.GuiTyping = TypingState.Typing;
game.GuiTypingBuffer = "";
game.IsTeamchat = false;
return;
}
if ((eKeyChar == chary || eKeyChar == charY) && game.GuiTyping == TypingState.None)
{
game.GuiTyping = TypingState.Typing;
game.GuiTypingBuffer = "";
game.IsTeamchat = true;
return;
}
if (game.GuiTyping == TypingState.Typing)
{
int c = eKeyChar;
if (game.platform.IsValidTypingChar(c))
{
game.GuiTypingBuffer = StringTools.StringAppend(game.platform, game.GuiTypingBuffer, game.CharToString(c));
}
int charTab = 9;
//Handles player name autocomplete in chat
if (c == charTab && game.platform.StringTrim(game.GuiTypingBuffer) != "")
{
IntRef partsLength = new IntRef();
string[] parts = game.platform.StringSplit(game.GuiTypingBuffer, " ", partsLength);
string completed = DoAutocomplete(parts[partsLength.value - 1]);
if (completed == "")
{
//No completion available. Abort.
return;
}
else if (partsLength.value == 1)
{
//Part is first word. Format as "<name>: "
game.GuiTypingBuffer = StringTools.StringAppend(game.platform, completed, ": ");
}
else
{
//Part is not first. Just complete "<name> "
parts[partsLength.value - 1] = completed;
game.GuiTypingBuffer = StringTools.StringAppend(game.platform, game.platform.StringJoin(parts, " "), " ");
}
}
}
}
示例9: OnKeyPress
public override void OnKeyPress(Game game_, KeyPressEventArgs e)
{
if (!visible)
{
return;
}
if (e.GetKeyChar() == 8) // backspace
{
return;
}
for (int i = maxColumns - 1; i > cursorColumn; i--)
{
buffer[cursorLine][i] = buffer[cursorLine][i - 1];
}
buffer[cursorLine][cursorColumn] = e.GetKeyChar();
cursorColumn++;
e.SetHandled(true);
}
示例10: KeyPress
void KeyPress(KeyPressEventArgs e)
{
for (int i = 0; i < WidgetCount; i++)
{
MenuWidget w = widgets[i];
if (w != null)
{
if (w.hasKeyboardFocus)
{
if (e.GetKeyChar() == 9 || e.GetKeyChar() == 13) // tab, enter
{
if (w.type == WidgetType.Button && e.GetKeyChar() == 13)
{
//Call OnButton when enter is pressed and widget is a button
OnButton(w);
return;
}
else if (w.nextWidget != -1)
{
//Just switch focus otherwise
w.LoseFocus();
widgets[w.nextWidget].GetFocus();
return;
}
}
}
if (w.type == WidgetType.Textbox)
{
if (w.editing)
{
string s = menu.CharToString(e.GetKeyChar());
if (e.GetKeyChar() == 8) // backspace
{
if (menu.StringLength(w.text) > 0)
{
w.text = StringTools.StringSubstring(menu.p, w.text, 0, menu.StringLength(w.text) - 1);
}
return;
}
if (e.GetKeyChar() == 22) //paste
{
if (menu.p.ClipboardContainsText())
{
w.text = StringTools.StringAppend(menu.p, w.text, menu.p.ClipboardGetText());
}
return;
}
if (menu.p.IsValidTypingChar(e.GetKeyChar()))
{
w.text = StringTools.StringAppend(menu.p, w.text, s);
}
}
}
}
}
}
示例11: OnKeyPress
public override void OnKeyPress(KeyPressEventArgs e)
{
game.KeyPress(e.GetKeyChar());
}