This is good to know. I am familiar with this call, and as far as I know this is really the only easy way of getting the scan code of a virtual key. The reason why I said what I did has to do with the fact that the keyboard hook already contains scan code info, so in order for it to output a scan code it didn't see it must be drawing from a list somewhere (in this case a call to OS using MapVirtualKey is used to get one such entry from OS's "list").
With some exceptions, AutoHotkey uses MapVirtualKey to determine the scan code if one is not received. This is handled in keyboard_mouse.cpp, vk_to_sc().
Unfortunately for me, and perhaps others as well, some machines do not have user available PS/2 ports, only USB. Oh well, you win some you lose some.
My Logitech wireless keyboard does this when the receiver is connected via USB. Fortunately for me, I use PS/2 (via an adapter.)
Yes, in my limited understanding, I agree that without using drivers or a combination of hook and Micha's USB HID support there is no way to differentiate among "physical" key presses without taking into account the injected flag. I was just surprised, for a moment when I first realized this, because hook hotkeys can be triggered by injected input, but getkeystate "P" doesn't accept it. But I soon realized why this is so. My statement was just to indicate to those who are interested what is the source for USB media keys being ignored by getkeystate "P".
If the injected flag is set, the event is "artificial." It is the way AutoHotkey can distinguish between physical key-presses and events sent by keybd_event (SendEvent), SendInput and similar.
Lexicos, since you have already been so kind as to answer me once, I would like to submit two more questions to you. You have stated that when you use your Logitech keyboard via USB you experience the same issues I have mentioned. What software support do you use for the keyboard? (Logitech Setpoint, Microsoft Intellitype, built in OS support, ...) I am just curious to see if other drivers may or may not give the same results.
Second question: Do you have any understanding as to what could be happening between the time when the scan code is first issued by the keyboard to the time the hook chain sees it that results in the scan code being set to 0 and the injected flag being set for media key presses on USB keyboards? I have not read anything meaningful pertaining to this issue so I would greatly appreciate any information you could share on this matter.