简体   繁体   中英

How can I use in wpf 2 keyboards?

How can I use in wpf 2 keyboard that connected to my computer(its part of a project) ?

For example, if I use "w", it will activate a button but on the second keyboard it won't activate it.

Use the Windows Raw Input API . It provides a way for applications to accept raw input from any HID, including keyboard and mouse.

You can use the Windows Raw Input API . Normally, windows intercepts keyboard input for you and makes it easier to deal with. Using the raw input API, you can deal directly with each keyboard instead of having windows treat both keyboards like a single keyboard. The downside is that the interaction will be much more low level. How you approach depends on your use case, but here are the main methods you probably care about in User32.dll:

  • GetRawInputDeviceList retrieves the list of input devices attached to the system.
  • RegisterRawInputDevices allows the application to register the input devices it wants to monitor.
  • GetRawInputData retrieves the data from the input device.
  • GetRawInputDeviceInfo retrieves information on a device.

You can import these methods to call them from C# for example like this:

[DllImport("User32.dll")] 
extern static uint GetRawInputDeviceList(IntPtr pRawInputDeviceList, ref uint uiNumDevices, uint cbSize);

EDIT: I haven't tried it before, but this library looks like it could give you a nice API for this kind of work. https://github.com/aelij/RawInputProcessor

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM