[英]Want to get input from Keyboard using windows api's
I want to get the keyboard input (single) using windows api's 我想使用Windows API获得键盘输入(单个)
i have two found option 1. keybd_event() of user32.dll
我有两个找到的选项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 2 user32.dll的SendInput()
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 ?? 我想将它们导入我的WPF应用程序中,我应该去哪一个?
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
. 由于您的目标是WPF,因此还需要将WndProc添加到
HwndSource
。
More information in this question: How to handle WndProc messages in WPF? 有关此问题的更多信息: 如何在WPF中处理WndProc消息?
[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) 来自PInvoke.net的更多信息: SetWindowsHookEx(user32)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.