简体   繁体   English

想要使用Windows API从Keyboard获取输入

[英]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. 两种选择。

RegisterHotKey RegisterHotKey

// 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消息?

SetWindowsHookEx SetWindowsHookEx

[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.

相关问题 使用C#从键盘获取输入? - get input from keyboard using C#? 在Windows 8中使用C#的原始输入获取HID键盘设备 - Get HID Keyboard Device Using Raw Input from C# in Windows 8 使用C#/ Windows API的虚拟键盘 - 发送键输入,但不要抓住焦点 - Virtual Keyboard using C#/Windows API - send key input, but don't grab focus 如何将键盘输入变成字符串而不在Windows窗体中显示呢? - How to get the keyboard input into a string without displaying it in windows forms? 在Windows环境中将输入从类似设备的键盘重定向到后台进程 - redirect input from keyboard like device to background process in windows environment 使用 JSON 从 Windows Phone 8 上的 API 获取信息 - Get info from API on Windows Phone 8 using JSON 我得到了数字键盘输入,我想保留其中的特定部分以备不时之需 - I get a keyboard input in numbers and i want to keep a specific section of them to use in cases 我想通过使用C#语言(Windows窗体)从Facebook获取用户信息和分析。 - I want to get users information and Analyse from facebook ,by using C# language (windows form) 从键盘输入到类 - Input from keyboard into Class 如何从 windows 中的当前键盘布局中获取文化信息? - How to get culture information from current keyboard layout in windows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM