Sending a command when the shortcut exists - autohotkey

I've got a global command like this
!i::Send {Up} (pressing alt+I will move the caret up)
There is an application that uses Alt+I as a shortcut for an action that I'd like to call while still retaining my own custom shortcut. I'd like to remap this app's action to Ctrl+I
Within a proper WinExists, I've tried ^i::Send !{i} but that just moves the caret up.
I tried ^i::!i but that sends Ctrl+Alt+I and not Alt+I.
Any ideas? Thanks

Gabe,
Try this...
SetTitleMatchMode, 2 ; Accept the title search string to be found anywhere in title
#ifWinnotActive yourappname ; use windowspy to find a unique title string
!i::Send {Up}
#ifWinActive
This will set !i to behave just like you want in ALL programs except for the one you want to keep the special behaviour.
Alternatively, you could add a $ to the triggers, so they will not call each other like this:
$!i::Send, {Up}
$^i::Send, !i

After each command, you need to add the command return. So if you have the code:
!i::Send, ^i
return
^i::Send, !i
return
The code above inverts the functions of CTRL + i and ALT + i.

Related

vscode: Is it possible to make (not remap) `caps lock` as one of the modifier keys?

I am not asking to remap Caps Lock to other modifier keys but I want to configure Caps Lock as one of modifier key for my own usage. Any ideas? :D
On Windows you can use AutoHotKey(usually briefly as ahk) with the WinActive function to make the ahk script only work when you're in vscode, mapping CapsLock+* keys to usually-not-used combinations like ctrl+shift+alt+* and write the ctrl+shift+alt+* keys to vscode's key configs.
It would roughly look like this:
; comment: the class used here is made up
; right click a running script in the system tray and go to "window spy" to get the right class name
; there are also usual `if`s but this one applies the condition to all the code following it
#If WinActive("ahk_class VSCode")
CapsLock & a::
SendInput, ^+!a
return
And of course if you want to get the function of capslock in the editor, you can easily use a combination like CapsLock & Shift to acomplish it like above.
For x11 OSes like most Linux distros, use xmodmap. Something like
keycode 66 = Alt_L Meta_L
clear mod1
add mod1 = Alt_L Meta_L
in your .Xmodmap file should suffice.
Then run:
xmodmap .Xmodmap

Autohotkey, putting "D89dl" at the end of a sentence doesn't work as intended

I have a Autohotkey script that puts "D89dl" at the end of a sentence everytime I press Enter, but using it with a AutoCorrect script it doesn't work as it should. Let's say you type "dont", it then would look like this "don't" instead of "don't.". Something is blocking it but I'm not sure what it is, I've been trying for months now.
Here are the scripts:
enter::
send,D89dl{Enter}
Return
#Hotstring EndChars -()[]{}:;'"/\,.?!`n `t
::dont::don't
I would be VERY thankful if anyone of you helps me with this.
Overall, do you know any other way instead of Autohotkey that puts "D89dl" at the end of a sentence?
The easiest solution seems to be to use the :*: mode, which will trigger everytime the misspelled word is typed, without the need for Hotstring EndChars:
:*:dont::don't
Instead of using Enter, I suggest you use a special combination of keys that enter the string D89dl and then press Enter. Use a modifier like ctrl or alt and another key. The reasoning is that the key Enter has very important functionality and should not be changed. Pressing that special combination is appropriate, given the very special function it does.
It's a bit hacky, but it should do the job (given that by "end of sentence" you actually meant pressing "Enter"):
~enter::
Sleep, 100
SendInput, {BS}D89dl{Enter}
Return
#Hotstring EndChars -()[]{}:;'"/\,.?!`n `t
::dont::don't

Creating a Mouse Hotkey

I've been using AHK in a very simple form for years, but multiple attempts at learning the more advanced functions has just resulted in confusion and frustration.
At the moment I'm trying to create a script that'll send the hotkey "CTRL + W" to Google Chrome when I hold the tilde key and left click inside the Google Chrome window. Whenever I trigger the script, it seems to close every single tab then the browser itself.
My script is below - what am I doing wrong?
#IfWinActive ahk_class Chrome_WidgetWin_1 ;Checks that the active window is Google Chrome.
` & LButton:: ;Tilde + Left Mouse Button
Send, ^+w ;Sends CTRL + W to the window.
return ;Ends the script.
Your script looks almost right. Try this. After you defined all the keys, you must "close" #ifwinactive ...
#IfWinActive, ahk_class Chrome_WidgetWin_1
` & LButton::Send, ^+w
#IfWinActive
Splitting the hotkey over multiple lines in not wrong, but in this case it can be done in one line. When you run into a problem like this. Try to isolate the issues. First ONLY try a bare ' & LButton::Send X to see if this works and be aware that you now loose the ` sign. Then try it with ^+w and when that works try it with #IfWinActive.
When you want to "restore" the tilde key, you could add this line:
~`::Return
The ~ will pass on the key data to the OS before executing the NOP (Return).

Remove auto modifier from hotkeys

Is there a way to make a hotkey with a modifier that doesn't automatically put the modifier on the output key? ex: ^a::b -- except, when I hit ctrl+a it just gives me ctrl+b, when I just want ctrl+a to = b.
Playing a game which for some reason won't let me use hotkey ctrl + keys so I'm circumventing the issue by setting the hotkeys as something out of the way then setting the actual hotkey I want to those keys in autohotkey.
Try:
^a::
Send, b
Send, c
Send, d
Return
or
^a::Send, bcd
Could you show the exact text of line 4 that causes the error?

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