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.
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.
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.
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.
IMHO, it's nigh impossible to find what you want quickly in the AHK documentation.
Here's a step by step.
Double click the AHK logo in the taskbar
Select View > Key History and Script Info
or press Ctrl + K
Type some junk like "Hello, world!"
View > Refresh
or press F5
. The key you pressed will be on the right. You may need to scroll down in the output window. 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:
- 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.
- Double-click that script's tray icon to open its main window.
- Press one of the "mystery keys" on your keyboard.
- Select the menu item "View->Key history"
- 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.
- If your key is detectable, make a note of the 3-digit hexadecimal value in the second column of the list (e.g. 159).
- To define this key as a hotkey, follow this example:
SC159:: ; Replace 159 with your key's value. MsgBox, %A_ThisHotKey% was pressed. return
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With