Many examples of using keybd_event, have the value 0x45 for the bScan parameter.
What is the meaning of that 0x45 value?
I was under the impression 0x45 was a keyboard scancode, but since it is used for a various number of keys, I'm not so sure about that any more.
My goal is to use keybd_event
either from .NET P/Invoke, or from Delphi, and make the types more restrictive (using for instance enums or flagged enums) so my code becomes easier to maintain.
It is indeed a scan code and for many keyboards it is the scan code for the NumLock key.
The example code attached to the documentation of keybd_event
is an example of how to toggle the NumLock state. And so naturally 0x45 is used as the scan code. My guess is that lots of the other examples that you found simply copied blindly that value from the keybd_event
MSDN example. Since applications typically ignore the scan code and respond to the virtual key code, it usually doesn't matter what value is passed as the scan code.
Finally, you'll want to use SendInput
rather than keybd_event
. The reason being that that former allows you to place a sequence of events in the queue. With keybd_event
you place the events in the queue one at a time and it's possible that your faked events can get interspersed with real events. And that problem is one of the main reasons why SendInput
was introduced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With