我正在嘗試將SendInput API用於熱鍵應用程序。所以我正在做的是有一個全局的keyhook,當一些keycombination命中我想發送另一個密鑰。SendInput ExtraInfo/Flags
我的問題是,當我發送模擬密鑰,然後我的鉤子收到該消息,我最終以遞歸循環。
因此,我嘗試過使用ExtraInfo/Flags,但由於某種原因,我設置的值與我在鉤子中收到的值不同。
var down = new INPUT();
down.Type = (UInt32)InputType.Keyboard;
down.Data.Keyboard = new KEYBDINPUT();
down.Data.Keyboard.KeyCode = (UInt16)keyCode;
down.Data.Keyboard.Scan = 0;
down.Data.Keyboard.Flags = 0; //doesn't matter whatever I set here... never gets back to my hook
down.Data.Keyboard.Time = 0;
down.Data.Keyboard.ExtraInfo = IntPtr.Zero; //doesn't matter whatever I set here... never gets back to my hook
不管我在ExtraInfo /標誌設置...它的復位,當我收到我的鉤消息:
private IntPtr KeyStateChangeCallback(int nCode, IntPtr wParam, ref KEYBDINPUT lParam)
{
//lParam.ExtraInfo and lParam.Flags ... is always some mumbo jumbo value or zero...
}
我使用lowlevelkeyboard鉤,「WH_KEYBOARD_LL」與設置是這樣的:
proc = KeyStateChangeCallback;
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
hookID = NativeMethods.SetWindowsHookEx(WH_KEYBOARD_LL, proc, NativeMethods.GetModuleHandle(curModule.ModuleName), 0);
}
其他人有類似的問題,可以幫我嗎?任何工作代碼示例將是太棒了:)
你使用什麼樣的鉤子? – shf301
謝謝:)我正在使用WH_KEYBOARD_LL鉤子,再次看看帖子 - 用附加信息更新它。 – user1831153