How to make both Alt keys work same way - autohotkey

I have some mappings that uses Alt key on Windows XP. While they work fine with
the left Alt, they doesn't with the right Alt key.
For example, the following mapping does nothing when I press right_Alt+b,
while it display a message box when left_Alt+b is pressed.
!b::MsgBox You pressed Alt+b.
I'd like to have both Alt keys to work the same way and trigger the mapping
above.
The mapping below does works with right Alt key, but doesn't works with left
Alt key:
<^>!b::MsgBox You pressed right Alt+b.
One workaround would be duplicate all mappings that contains the alt key, but
that would significantly increase the size of some scripts. Besides, I found
that in some cases it doesn't works. Further investigation showed that the
right alt key has a strange behavior. In a script containing only the
following mapping,
^!b::MsgBox You pressed Ctrl+Alt+b.
, the message box is displayed when right_Alt+b is pressed.
I've tried to map right Alt to left Alt,
<^>!::!
or
<^>!::Send {ALT}
, but it didn't solve the problem.

You mention that you tried to map the Right-Alt to Left-Alt, but not HOW you did this. Anyway, when I use this:
RAlt::LAlt
MsgBox You pressed Alt+b. is executed when I press Right-Alt+b AND Left-Alt+b.
Can you tell how you tried to map the two Alt keys?

I write this comment as an answer because of the better formatting options.
Here is the script I used in AutoHotKey_L (1.1.09.01), should work the same in regular AutoHotKey.:
RAlt::LAlt
<^>!b::MsgBox, A You pressed right Alt+b.
^!b::MsgBox, B You pressed Ctrl+Alt+b.
Test 1: pressed Ctrl+LAlt+b. Result: MsgBox B, normal behaviour
Test 2: pressed Ctrl+RAlt+b. Result: MsgBox B, expected due to the re-mapping
Commented the ;^!b::MsgBox, B... out and tested again.
Test 3: pressed Ctrl+RAlt+b. Result: Nothing, as expected
Commented ;RAlt::LAlt out and tested again:
Test 4: pressed Ctrl+RAlt+b. Result: MsgBox A, expected since no more re-mapping.
Last but not least. There is NO difference in behaviour if I press Ctrl+RAlt+b or RAlt+Ctrl+b. One more note: I always used the LEFT Ctrl key, not the RIGHT Ctrl key.
Are you NOT getting these results?
Or are you expecting different results when you make RAlt equal to LAlt?

Related

Having problem with using Virtual keyboard code in Autohot Key

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>

Match both shift keys being pressed in AutoHotKey

One of my keyboards has a larger Shift key where my pipe/backslash key normally is. Is there a way to match Shift-Shift in AutoHotKey (i.e. both Shift keys pressed) so that I can still type pipes (|) in the way I would with my other keyboards? I have tried simply ++ but that seems to equate to Shift-+.
Thanks to #0x464e's comment, I was able to find the Virtual Key codes (VKs) for left shift and right shift by:
Adding ++::Send {U+007C} to my ahk script (right of the :: is irrelevant here, this is just so that Shift shows up in the key history)
Right click the script in the system tray, click Open, select Key History in the View tab.
Type Shift-+ a few times with each Shift key into a text editor.
Hit F5 in the Key History window and read off the values for Virtual Key for Left Shift and Right Shift (VKA0 and VKA1 respectively in my case).
Then I added the following rules to my ahk script to send a pipe whenever I held the Right Shift key and pressed the Left Shift key:
VKA1 & VKA0::Send {U+007C}

AHK for enter and arrow key

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

Trying to recognize Fn + V on my keyboard

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).

Autohotkey: Commands with Alt Key Working Properly only if not Restricted to a Specific Application

I'm trying to add custom keyboard commands to an application using Autohotkey.
In many of these hotkeys I would like to use the alt key in combination with some other key of my choice (any of the standard letters).
All works fine as long as I don't restrict their usage in such a manner that they work in the target application only (via the #IfWinActive directive ). If I do so, the hotkeys themselves still work, however their behavior is very strange.
I found that they get activated either if
a) I hold down the alt key and then press the second key (in my case the 'b' key) twice
or
b) I use this hotkey two times consecutively with a very short delay between the two triggerings
- The above two cases might actually be 1 case. I'm not sure...
I have no problems when doing the same with Shift or CTRL.
The 'b' key is not what's causing the problem - no alt + 'letter' combination works.
I have tried all SendModes, but so far with no effect.
Code sample:
#IfWinActive, MyAppTitle ahk_class MyAppClass
!b::
click 367, 86
return
Alt+letter commands in AutoHotkey such as !b work without issue. It's possible the version at the time of this post contained certain bugs or was out of date from the current version.
For your code, it could be done like so:
!b::
WinGetTitle, Title, A
if (RegExMatch(Title, "MyAppTitle"))
{
MouseClick, left, 367, 86
}
return