6
votes

I just started using autohotkey and I already got 1 question:

Is there a way to detect which button is 'pressed' without listing any keys that it should look for? As in, detect ANY button pressed.

The reason I want this is because I'm trying to figure out if there is a way to detect the volume up/volume down keys on my earphones. I want to know if autohotkey can, somehow, detect them and if it does, what 'keyword' it assigns to it.

Note:

The volume up/down buttons on my earphones aren't 'recognized' by Windows on default. So they don't work as media buttons, which I do try to achieve.

3
Follow the steps described under Special keys.MCL
This is the answer I was looking for. Thank you. It seems it doesn't detect the 'buttons' though. The buttons do volume up/down on ios devices. Thought I'd be able to catch it in autohotkey somehow. Thanks.MrSoundless
Where do you plug those earphones, in the stereo jack? I don't think a PC can receive signals from there.MCL

3 Answers

8
votes

IMHO, it's nigh impossible to find what you want quickly in the AHK documentation.

Here's a step by step.

  1. Double click the AHK logo in the taskbar
    enter image description here

  2. Select View > Key History and Script Info or press Ctrl + K enter image description here

  3. Type some junk like "Hello, world!"

  4. Select View > Refresh or press F5. The key you pressed will be on the right. You may need to scroll down in the output window.

enter image description here

2
votes

As MCL mentioned, you can try the steps for Special Keys in AutoHotkey's documentation.

(Note: This may not work for headphone volume buttons, as most PC headphone jacks don't support 3 stripe TRRS signals)

Special Keys

If your keyboard or mouse has a key not listed above, you might still be able to make it a hotkey by using the following steps:

  1. Ensure that at least one script is running that is using the keyboard hook. You can tell if a script has the keyboard hook by opening its main window and selecting "View->Key history" from the menu bar.
  2. Double-click that script's tray icon to open its main window.
  3. Press one of the "mystery keys" on your keyboard.
  4. Select the menu item "View->Key history"
  5. Scroll down to the bottom of the page. Somewhere near the bottom are the key-down and key-up events for your key. NOTE: Some keys do not generate events and thus will not be visible here. If this is the case, you cannot directly make that particular key a hotkey because your keyboard driver or hardware handles it at a level too low for AutoHotkey to access. For possible solutions, see further below.
  6. If your key is detectable, make a note of the 3-digit hexadecimal value in the second column of the list (e.g. 159).
  7. To define this key as a hotkey, follow this example:

SC159:: ; Replace 159 with your key's value.
MsgBox, %A_ThisHotKey% was pressed.
return
0
votes

You can use <KeyHistory> to get which keys you are/have pressed. Once that is determined, you can then use <GetKeyState> to see if the key has been pressed or not.