I want to get the keyboard input (single) using windows api's
i have two found option 1. keybd_event() of user32.dll
VOID WINAPI keybd_event(
_In_ BYTE bVk,
_In_ BYTE bScan,
_In_ DWORD dwFlags,
_In_ ULONG_PTR dwExtraInfo
);
2 SendInput() of user32.dll
UINT WINAPI SendInput(
_In_ UINT nInputs,
_In_ LPINPUT pInputs,
_In_ int cbSize
);
i want to import them in my WPF app which one should i go after ??
Two alternatives.
// Registers a hot key with Windows.
[DllImport(“user32.dll”)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
// Unregisters the hot key with Windows.
[DllImport(“user32.dll”)]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
Since you are targeting WPF you would also need to add a WndProc to your HwndSource
.
More information in this question: How to handle WndProc messages in WPF?
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetWindowsHookEx(HookType hookType, HookProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool UnhookWindowsHookEx(IntPtr hhk);
More information from PInvoke.net: SetWindowsHookEx (user32)
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.