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
~Media_Next::

If GetKeyState("Media_Next", "P")

	MsgBox, Media_Next down

Return
This somewhat unexpectedly never generates the msgbox, although I can see, from script history, that the hotkey is called. From what I've read

This can be just about any single character from the keyboard or one of the key names from the key list, such as a mouse/joystick button (though mouse button state usually cannot be detected on Windows 95/98/Me).

I am unaware of any such limitation of the media keys for GetKeyState. Does anybody know what could be going wrong?
- Tertius

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Does anybody know what could be going wrong?


Looks like a bug to me..
kWo4Lk1.png

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
.. a workaround

~VKB0:: ; Media_Next is 0xB0
Sleep 1000
KeyDown := !! DllCall( "GetKeyState", Int,0xB0, Short) 
MsgBox, % KeyDown   
Return

To find ScanCode / Virtual Key :
Crazy Scripting : Scriptlet to find Scancode of a Key posted by SKAN

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
What about Logical instead of physical?

does the keyhistory window show a key up event?

I expect that the key quickly sends a down and an up when you press it, so as far as the PC is concerned, you have already let go of the button, even though you haven't.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I expect that the key quickly sends a down and an up when you press it


If that is the case, how is my code able to detect it ? :roll:
kWo4Lk1.png

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
I think your code is checking the physical state, while logically, it has already been released? I'm afraid I am unable to answer confidently, since I don't have a suitable keyboard with which to test. I am speculating.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I think your code is checking the physical state


so does Tertius' code! but it is not working..

Edit:

What about Logical instead of physical?


but you were right, the following works:

~Media_Next:: 
If GetKeyState("Media_Next") 
   MsgBox, Media_Next down 
Return

:)
kWo4Lk1.png

Tertius
  • Members
  • 62 posts
  • Last active: Aug 07 2008 11:43 AM
  • Joined: 05 Jun 2008
This dllcall to getkeystate is to retrieve the logical state. The getkeystate "P" requires a hook to be in place, else it reverts to getkeystate without the "P", and seems to be implemented by storing the virtual keycode of key presses as they come and are processed by the hook. It seems that the media key presses are not stored by AutoHotkey. Also, here's evidence that the scan code does not seem to be used by GetKeyState "p", only the virtual key code
~NumpadHome::

If GetKeyState("Home", "P")
	MsgBox, Home Down
Else If GetKeyState("NumpadHome", "P")
	MsgBox, NumpadHome Down
Return
You will find that the first call to GetKeyState is the cause for the resulting msgbox, the only difference between the numpadhome and home keys is their scan code (same virtual key code).

As far as I can tell, based off mine and other (more experienced) users finding the same, this appears to be a bug. Please correct me if I am wrong.
- Tertius

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

this appears to be a bug. Please correct me if I am wrong.


Should this topic be moved to Bug Reports ?
kWo4Lk1.png

Tertius
  • Members
  • 62 posts
  • Last active: Aug 07 2008 11:43 AM
  • Joined: 05 Jun 2008

Should this topic be moved to Bug Reports ?

Yes, I believe so.

SKAN and engunneer, thank you for taking the time and effort to look into this.
- Tertius

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
I don't think it is a bug (yet). The problem is not that it is not stored by AHK, but in fact that the hardware driver is releasing the key (prob something to do with typematic delay?)

Does this happen with any other Media_* keys?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I don't think it is a bug (yet).


Yet, let this topic attract the attention of Mr.Chris

The problem is not that it is not stored by AHK, but in fact that the hardware driver is releasing the key (prob something to do with typematic delay?)


:idea: Could be.. I am using USB Keyboard.. Should check it with a PS2

Does this happen with any other Media_* keys?


All of the Media Keys..

:)
kWo4Lk1.png

Tertius
  • Members
  • 62 posts
  • Last active: Aug 07 2008 11:43 AM
  • Joined: 05 Jun 2008
Thanks again engunneer for trying to resolve this.

I don't think it is a bug (yet). The problem is not that it is not stored by AHK, but in fact that the hardware driver is releasing the key (prob something to do with typematic delay?)

I don't believe this to be so, unless this is unique to the media keys. However, the following test should confirm that typematic delay is not the issue
; On my Machine I have a 500 ms delay before autorepeat kicks in
~Media_Next::
Loop 20
{
	If GetKeyState("Media_Next", "P")
		MsgBox, Media_Next down ; This is never called
	Sleep 50
}
Return



Does this happen with any other Media_* keys?

I have tested both Media_Next and Media_Prev. Perhaps later I will test the others.
- Tertius

Tertius
  • Members
  • 62 posts
  • Last active: Aug 07 2008 11:43 AM
  • Joined: 05 Jun 2008
Ah, it is related to USB. SKAN and I both encountered problems with USB keyboards, but my PS/2 keyboard works fine. I am sad because I cannot use my favorite keyboard like I want to for a script.
- Tertius

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I am sad because I cannot use my favorite keyboard for a script.


Why not remove "P" ? The following works in my USB KB fine..

~Media_Next::
If GetKeyState("Media_Next") ; "P" Removed
   MsgBox, Media_Next down
Return

:)
kWo4Lk1.png