I'm working on a C# application that allows a user to configure a control profile for an emulator. Part of that involves binding keyboard keys to controller buttons, and is done through a clickable "on-screen keyboard" dialog. Today, I decided to add keyboard recognition to the dialog window, so that the user can simply press a key on his keyboard to map it.
It's working, apart from the fact that I don't seem to have any way of telling apart the numpad enter key with the regular enter. This is something I need to fix, but can't find any info on how this could be done.
The current
code kludge handling the keyboard input in this part of my application is below:
Code:
[DllImport("user32.dll")]
static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
private bool IsKeyPressed(Keys key)
{
if (Convert.ToInt32(GetAsyncKeyState(key).ToString()) == -32767)
return true;
else
return false;
}
protected override bool ProcessDialogKey(Keys keyData)
{
if (IsKeyPressed(Keys.LShiftKey)) button55.PerformClick();
else if (IsKeyPressed(Keys.RShiftKey)) button28.PerformClick();
else if (IsKeyPressed(Keys.LMenu)) button69.PerformClick();
else if (IsKeyPressed(Keys.LControlKey))
{
if (IsKeyPressed(Keys.RMenu)) button70.PerformClick();
else button67.PerformClick();
}
else if (IsKeyPressed(Keys.RControlKey)) button68.PerformClick();
else if (IsKeyPressed(Keys.RMenu)) button70.PerformClick();
else switch (keyData)
{
case Keys.Escape: button1.PerformClick(); break;
// there's 90-something lines of the same thing repeated, differentiated only between different Keys enums and buttons.
case Keys.Right: button81.PerformClick(); break;
default:
break;
}
return true;
}