I hook keyboard event using:
HookManager.KeyUp += new KeyEventHandler(HookManager_KeyUp);
Then wait for keyboar event by:
public void HookManager_KeyUp(object sender, KeyEventArgs e)
{
StepInfo step = new StepInfo();
step.keyALT = e.Alt;
step.keyCTRL = e.Control;
step.keySHIFT = e.Shift;
step.KeyHandle = e.Handled;
step.keySuppress = e.SuppressKeyPress;
step.keyCode = e.KeyCode;
step.keyData = e.KeyData;
step.keyValue = e.KeyValue;
step.modifiers = e.Modifiers;
}
I want to check the combination key shift , ctrl , alt and other control key. Example: shift + a , ctrl + f .. etc But I all e.KeyData, it return only letter key like A, B, C but the e.Alt, e.Shift, and e.Control always be "false" value.
How can I check that, does user press A or shift + A .
You may find GetKeyboardState function useful in your case:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646299(v=vs.85).aspx
Implementation could be like this:
[DllImport("User32.dll",
EntryPoint = "GetKeyboardState",
CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern Boolean CoreGetKeyboardState(Byte[] value);
public static Boolean IsKeyDown(Keys key) {
Byte[] data = new Byte[256];
if (!CoreGetKeyboardState(data))
return false;
return ((data[(int) key] & 0x80) == 0x80);
}
...
if (IsKeyDown(Keys.A) &&
(IsKeyDown(key.Menu) || IsKeyDown(key.ShiftKey) || IsKeyDown(key.ControlKey))) {
//TODO: You code here
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.