Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Physical State of Media Keys not detected by GetKeyState


  • Please log in to reply
33 replies to this topic
Tertius
  • Members
  • 62 posts
  • Last active: Aug 07 2008 11:43 AM
  • Joined: 05 Jun 2008
Lexicos, thanks so much for looking into this. I understand you are quite familiar with AutoHotkey source code, so your input is much needed.

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().

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").

My Logitech wireless keyboard does this when the receiver is connected via USB. Fortunately for me, I use PS/2 (via an adapter.)

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.

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.

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

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

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

What software support do you use for the keyboard?

I haven't used SetPoint since I stopped using the mouse that came with my keyboard. SetPoint constantly complains that the mouse batteries are critical, but in fact there aren't any. :roll: I'm not sure whether the drivers I'm using are ones installed by SetPoint or default Windows drivers. Device Manager shows the Driver Provider as "Logitech."

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?

Perhaps the media keys are handled by the driver at too late a stage - or in the wrong way - to be reported as actual key events. It seems the driver injects "artificial" events using only the virtual keycode - i.e. the scan code is never used.

There is no way of knowing, except to ask the author of the driver...

Tertius
  • Members
  • 62 posts
  • Last active: Aug 07 2008 11:43 AM
  • Joined: 05 Jun 2008
Lexicos, thanks so much for answering. I wish I could help you out on that annoying SetPoint battery notification, but I am unfamiliar with that software.

It seems the driver injects "artificial" events using only the virtual keycode - i.e. the scan code is never used

I know that this has to involve USB HID Service so perhaps this service injects such events, unlike the rest of the keys on the USB keyboard which just come in clean without being injected.
- Tertius

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006

I wish I could help you out on that annoying SetPoint battery notification

Before I stumbled across AHK, I found the file C:\Documents and Settings\User0001\Application Data\Logitech\SetPoint\user.xml which contains the following lines:
<Device Class="Receiver" Model="50331689">
         <Param AppSpecific="1" LowBatPercentLevel="5" UserBatteryMode="0" VScrollAcceleration="0" VScrollSpeed="0" VoIPClient=""/>
         <Buttons/>
      </Device>
Setting LowBatPercentLevel="-1" might disable logitech's low battery nag, though Lexikos probably has no need for setpoint anymore.