From the error I explained in my previous question It turns out I should use Virtual Keyboard code for the keys that I face error.
I want to use virtual code for hotkey +' (Which is pressing Shift and ' at the same time) and for the key ; (semi-column) (more specifically I want to use hotkey +' to click on a coordinate and the key ; to click on other coordinate) but I have problem writing the code. I found list of Virtual Keys here but unfortunately I don't know how to use them to write code.
Edit:
For pressing semi-column (;) I tried this key:
[vkBA27]::
Click,885,234
return
But It says it is invalid hotkey.
From the AutoHotkey documentation:
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
Interpreting the example above, we know that the format for a hotkey declaration using a virtual key is:
SC<Hex code>::
<Your code here>
Return
I can only assume "SC" stands for "Scan Code". Using the steps above, I can see that the scan code (the documentation refers to it as the "3-digit hexadecimal value") for ; is 027, and the scan code for ' is 028. This allows me to construct your hotkey definitions like so:
SC027::
<Your code for ; here>
+SC028::
<Your code for SHIFT+' here>
Related
Can't seem to find this simple script anywhere. I'm trying to create a script that runs when the enter and right arrow key is pressed.
Here's what I've tried so far:
{Enter}{Right}::
Send, #tab
return
I know it must be something really simple but can't find the solution anywhere!
Here's the documentation link for hotkeys:
https://www.autohotkey.com/docs/Hotkeys.htm
And in there, after understanding the basics, you're interested in this part of it:
https://www.autohotkey.com/docs/Hotkeys.htm#combo
And assuming by #tab you mean pressing Windows key and the Tab key, you want to look at this page of the documentation:
https://www.autohotkey.com/docs/misc/Remap.htm
(If you wanted to use the Send command, it'd be Send, #{Tab})
You should end up with this:
Enter & Right::#Tab (have to press enter before right arrow key)
And that works, though you're probably going to want to add one little addition, which the ~ modifier.
It'll make it so your Enter key also works on itself while the script is active.
So you'd end up with this:
~Enter & Right::#Tab
Though, now you'll always send a Enter keystroke every time you run the hotkey, which might not be good, I recommend switching it around to:
~Right & Enter::#Tab
I hate that when I'm using my laptop on its own I often type FN+v when I mean to paste. So I decided to solve my problem with AHK. I installed a keyboard hook in my main script,and used that to extract the fn keys value, 163. My initial test worked, but adding the & to make it a modifier does not. What am I overlooking?
So this doesn't work
SC163 & v::
MsgBox, %A_ThisHotkey% was pressed.
return
but this did work
SC163::
MsgBox, %A_ThisHotkey% was pressed.
return
When you hit the FN key, it might be remapping the "v" to something else (like "Media_Play_Pause" button) in the keyboard driver. Therefore the key code wouldn't be SC163 & v but something like SC159.
The Special Keys section for mentions a method to get the Scan code:
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 Special Keys.
If your key is detectable, make a note of the 3-digit hexadecimal value in the second column of the list (e.g. 159).
Within the steelseries engine it is very easy to change the basic key functionality. But I can not find an option to change what happens when you press a modifier key like 'shift' + that specific key.
I was wondering if anyone knows either a way of doing this in Steelseries engine, or another way perhaps using AHK or something of the sort?
It depends on what you are trying to do with the key binding. But yes you can capture shift+ another key with the syntax below.
+A::
MsgBox, Shift A was pressed!
return
+B::
Send, Shift B was pressed!
Return
To see a full list of the modifier hotkeys and the symbol to use for each you can look at Hotkeys
I created the Menu for my Matlab GUI which is "File" under which sub menus are Open, Save & Exit.
When i clicked on the File Menu, it will list down the sub menu items Open, Save & Exit.
I want to assign a shortcut key for this file menu instead of clicking the file menu when i press the "Alt+F" it has the show the list down of sub menu items. I dont want to use the shortcut option provided by the Guide, i want to hard code that shortcut Key.
I have coded for the combination of the key detection (Alt+F) but which function/call back has to be used for the listing down of the sub menu items ?
https://ece.uwaterloo.ca/~nnikvand/Coderep/gui%20examples/GUI.pdf
page 37
MATLAB menus support accelerator keys and keyboard mnemonics. Accelerator keys are "CTRL+key" combinations that cause a menu item to be executed without opening the menu first.
For example, the accelerator key "0" might be assigned to the File/Open
menu item. In that case, the keyboard combination CTRL+o will cause the File/Open callback function to be executed.
A few CRTL+key combinations are reserved for the use of the host operating system.
These combinations differ between PC and UNIX systems; consult the MATLAB online documentation to determine which combinations are legal for your type of computer. Accelerator keys are defined by setting the Accelerator property in a uimenu object.
Keyboard mnemonics are single letters that can be pressed to cause a menu item to execute once the menu is open. The keyboard mnemonic letter for a given menu item is underlined. For top-level menus, the keyboard mnemonic is executed by pressing ALT plus the mnemonic key at the same time. Once the top-level menu is open, simply pressing the mnemonic key will cause a menu item to execute. Figure 1.29 illustrates the use of keyboard mnemonics. The File menu is opened with the keys ALT+f, and once it is opened, the Exit menu item can be executed by simply typing "x".
Keyboard mnemonics are defined by placing the ampersand character (&) before the desired mnemonic letter in the Label property. The ampersand will not be displayed, but the following letter will be underlined, and it will act as a mnemonic key. For example, the Label property of the Exit menu item in Figure 1.29 is 'E&xit'.
I have written a python script for my co-workers, and then created an autohotkey script to run it every time someone presses Ctrl+LShift+Y. Looks something like this:
^+y::Run helper.py
The python script is fine, but the ahk script doesn't work on all the computers. Sometimes it works fine, and sometimes you get this error:
^+y does not exist in current keyboard layout
Now, searching the web this seems to be a problem with multi-language keyboards (we're using both Hebrew and English), because different languages means a different layouts (I guess?). I also found someone explaining that to solve this you need to use scan codes instead of the usual ^ and + and so on (I'd link to it but I cannot seem to find it now).
This all vaguely makes sense to me on a theoretical level, but when I want to realize it with actual code, I don't really know what to do. To me it seems as if this topic is hardly discussed (with the few exceptions being lacking in examples or hard to understand), so I'd love an answer that would include the following:
some simple way of determining the scan code for a key. This should preferably be a pythonic solution (and just out of curiosity, I'd love to know how to do this with linux as well). This is probably the easier part (but I think is an inherent part of a complete answer).
This is the important part: examples of how you implement that scan code in an autohotkey script, including edge-cases (if there are any).
Question 1
As you want to use the key with autohotkey, it makes sense to use autohotkey detect the key in the first place. Obviously this method works only on windows where autohotkey is running.
Write a Autohotkey script with this line and run it.
#InstallKeybdHook
Press the key you want to examine.
Open the script menu by right clicking the icon of the script in the right lower corner of your screen.
Select OPEN, then from the Menu "View / Key history and script info"
There is a line for each keypress.
First column is the VK (Virtual key) code, next is the scancode.
For example for CAPSLOCK the VK is 14 and the Scancode 03a
Question 2:
#InstallKeybdHook
VK14::
msgbox, you pressed capslock!
return
OR
#InstallKeybdHook
SC03a::
msgbox, you pressed capslock!
return
both work.
Note that you can combine two keys into a hotkey by combining them with & (but not 3)
#InstallKeybdHook
RShift & SC03a::
msgbox, you pressed Rshift capslock!
return
You can modify a Scancode with + and ^
#InstallKeybdHook
^+SC02C::
msgbox, you pressed Ctrl Shift and Y(maybe)!
return
Further info about this is on the page "List of Keys, Mouse Buttons, and Joystick Controls" of the autohotkey help file that comes with the default installation.