11

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.

MrSoundless
  • 1,246
  • 2
  • 12
  • 34
  • 3
    Follow the steps described under [Special keys](http://www.autohotkey.com/docs/KeyList.htm#SpecialKeys). – MCL Sep 09 '13 at 08:06
  • 1
    Where do you plug those earphones, in the stereo jack? I don't think a PC can receive signals from there. – MCL Sep 09 '13 at 09:48

4 Answers4

15

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

Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
  • 2
    This doesn't work in AHK 1.1.33.0, at least not on 64-bit Windows 10 Home 1903 OS build 18362.959, and I can't find the new method (if any). Specifically, double-clicking the AHK logo in the taskbar does not do anything. No sound, no window, no nothing. –  Jul 27 '20 at 17:41
  • Weird. I don't have a Windows PC handy. Looks like they have a 1.1.33.02 release available on their homepage. Looking at Git, I don't see anything in the release notes about that. Maybe file a bug if the latest doesn't fix your issue: https://github.com/Lexikos/AutoHotkey_L/tags – Lorem Ipsum Jul 27 '20 at 20:53
  • At least as of v1.1.33.06, one has to include the following statement in the script: `#InstallKeybdHook` – AndyO Apr 17 '21 at 11:01
5

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
Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
1

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.

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Kirito
  • 11
  • 2
0

A bit of a struggle but I managed to figure it out. You need to have a script running to check out the "Key history & key info" window but that feature behaves differently based of the contents of the script you run.

Since I downloaded AHK for this purpose specifically I was using the first example script in the docs as my dummy script which only shows its own output & nothing about other keys pressed

^j::
Send, My First Script
return

Doing the same thing but running this other script I managed to record the keys I needed, hope this helps others with the same issue as me

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