Hallo.
I have 3 keyboards connected to th computer.
I need to detect all keyboards connected and, when I press a key on a keyboard, to detect that key with the keyboard used.
Thank you very much
https://devblogs.microsoft.com/oldnewthing/20160627-00/?p=93755
The link above refers a blog article from an engineer at Microsoft where some sample C/C++ code is provided to demonstrate capturing raw input. When capturing raw input, it is possible to distinguish between input received from multiple input devices of the same type, such as keyboards or mice. Higher level handling of input such as the Windows messages generated for a GUI application that register keyboard input and mouse movement will not provide the source device information, so usage of raw input capture is necessary. The C/C++ code could be adapted to C# code making use of PInvoke and then dynamically compiled within a WinBatch script. Alternatively, WinBatch might possibly be able to utilize its DllCall() function, but that's somewhat "iffy" in this case.
Nice reply Chuck. That article does have some code snippets. Maybe the OP can experiment.
Quote from: ChuckC on June 06, 2022, 07:05:03 AM
https://devblogs.microsoft.com/oldnewthing/20160627-00/?p=93755
The link above refers a blog article from an engineer at Microsoft where some sample C/C++ code is provided to demonstrate capturing raw input. When capturing raw input, it is possible to distinguish between input received from multiple input devices of the same type, such as keyboards or mice. Higher level handling of input such as the Windows messages generated for a GUI application that register keyboard input and mouse movement will not provide the source device information, so usage of raw input capture is necessary. The C/C++ code could be adapted to C# code making use of PInvoke and then dynamically compiled within a WinBatch script. Alternatively, WinBatch might possibly be able to utilize its DllCall() function, but that's somewhat "iffy" in this case.
If the window creation business is ignored there doesn't appear to be anything in the sample that couldn't be handled with the judicious use of DllCall and DllCallBackCreate. Admittedly, it would be tricky and require a good amount of trial and error.
Very interesting, but that is C language... :-(
Just another opportunity to learn ;)
Jim
Not being able to understand the C/C++ language will be a major impediment to understanding the sample code that I posted a link to.
To put a question back in the OP's court:
What drives the need to know which keyboard was used to generate a key press event?
As far as Windows is concerned, it doesn't specifically care which device generated the event, and it abstracts the low-level interaction with a keyboard device so that applications are made aware of the key press event regardless of which device generated it.
I have much than 3 keyboards connected to the computer and I need to know which keyboard generates the character to send that character to the right window.
Here is some foundational reference material that you need to read and develop an understanding of:
https://docs.microsoft.com/en-us/windows/win32/learnwin32/learn-to-program-for-windows
https://docs.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input
https://docs.microsoft.com/en-us/windows/win32/inputdev/keyboard-input
https://docs.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input
https://docs.microsoft.com/en-us/windows/win32/inputdev/using-keyboard-input
https://docs.microsoft.com/en-us/windows/win32/inputdev/keyboard-input-reference