Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect what 'button' is pressed

Tags:

autohotkey

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.

like image 718
MrSoundless Avatar asked Sep 09 '13 08:09

MrSoundless


People also ask

How do I know if my button is clicked?

To check if a button is clicked, first we need to access the button element inside the JavaScript using the document. getElementById() method, then add a click eventListener to it. In the code above, we have added an alert button is clicked inside the addEventListener() method.

How do you know if an element is clicked?

To check if an element was clicked, add a click event listener to the element, e.g. button. addEventListener('click', function handleClick() {}) . The click event is dispatched every time the element is clicked. Here is the HTML for the examples in this article.

How do I know which button is pressed in Swift?

cause first is you have to click from the 3 button after clicking from the 3 button then you will click idenfifywhichpressed button and this button will identify or print which button from the 3 was pressed. During setup, mark the button tag as 1,2,3... When your click action done, check the sender.


2 Answers

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

like image 117
Lorem Ipsum Avatar answered Sep 19 '22 14:09

Lorem Ipsum


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
like image 25
Stevoisiak Avatar answered Sep 18 '22 14:09

Stevoisiak