Autohotkey - multiple scripts and different language issues - autohotkey

I use autohotkey to simplify copying, using Alt+W instead of Ctrl+C. However, I often switch my keyboard to a Hebrew layout, so the w key is now the ' key. Then the autohotkey script for w doesn't work.
I tried to write a second script into the same file but it doesn't get activated when I press Alt+' when I'm in the Hebrew layout. I'm not sure whether it's my syntax or something else, any ideas?
This is my code:
!w::
Send, {ctrl down}{a down}{a up}{c down}{c up}{ctrl up}
return
!'::
Send, {ctrl down}{a down}{a up}{c down}{c up}{ctrl up}
return
Thanks!

Catching Alt-' with the code you used works in other keyboard layouts (like the German layout) so your syntax looks OK to me.
To solve your problem I'd start the autohotkey help file.
Read "List of Keys, Mouse Buttons, and Joystick Controls"
where the section on "Special Keys" explains how to attempt
to catch inrecognized keys via the "keyboard hook".
Basically it describes how to find out the !' scancode which
you then can use as a hotkey alternative.

It is worth to try to use the virtual/scan codes of keys, instead names, This example uses the virtual code (vkXX):
;~ SetKeyDelay, keyDelay:=25, pressDuration:=25 ; details for SendEvent mode.
!vk57:: ; w/'/я... (en/he/ru...)
Send, {CtrlDown}{vk41}{vk43}{CtrlUp}
KeyWait, vk57
;~ Do something by release this key, if necessary...
Return

Related

I want to simply make a script for send "arrow right" in autohotkey

I want to simply make a script for send "2x arrow right" in autohotkeys. I now have:
^Tab::
Send,
return
After Send, I tried several combinations, some of them being {right}, {Right}, plus over 10 more combinations I found on the net which supposed to perform the difficult task of arrow right, but none which managed to work. Only thing I want is to Send, [insert some words which will do the trick] to have autohotkeys perform "2x arrow right". Would make my life a lot easier during programming. Who can help me out?
No need for Return for single-line statements. Keys can be repeated as so:
^Tab::SendInput {Right 2}
See more about repeating keys with Send[Raw|Input|Play|Event] and about using SendInput instead of Send here: https://www.autohotkey.com/docs/commands/Send.htm#SendInputDetail
Switched from Send to SendInput for reliability.
The easiest way to solve this would just be to make your script send two SendInput, {right} one after another.
For Example:
^Tab::
SendInput, {right}
SendInput, {right}
return
If you needed it to loop a finite number of times, you could use this instead:
^Tab::
Loop 2 ;replace '2' with however many times you want the next line to repeat
SendInput, {right}
return
Sidenote: In the context that I am using it, return just means to stop executing a multi-line hotkey. What your example above does is send the word "return". If you want to send a special key like the right arrow button or the return/enter key, you would have to enclose it in curly braces {}. For example, {right} or {return} corresponding to the aforementioned examples. For more information about this, please see this documentation link.

How to make script to paste something in with AutoHotKey

I'm trying to make a script in AutoHotkey where, when I press Numpad 1, it presses the slash button, then pastes in some text, let's say "hello world", and then presses enter, but I can't figure out how. Can someone help?
Welcome to Stack Overflow.
In the future, try to at least show what you tried. All of this should be accomplished pretty easily by e.g. looking at the beginner tutorial combined with a quick Google search.
But well, here it is:
Numpad1::
Clipboard := "/hello word"
SendInput, ^v{Enter}
return
Numpad1:: creates the hotkey label.
Clipboard:= ... puts something into the clipboard.
SendInput sends input.
^v means Ctrl+v.
{Enter} means the enter key (could've possibly appended `n (line feed) into the string as well).
Return stops the hotkey label's code execution (in other words, ends the hotkey's code).
Assuming that you already have some text copied inside your clipboard before pressing the numpad1, the following code will work.
Numpad1::
Send, /^v ; ^ means ctrl key,
Send, {Enter}
return

Shortcuts key replacemento with AutoHotkey

I just started using Autohotkey (I am a noob with it) for remapping some key combinations like CTRL+TAB (which is good if you are using your left hand) to be accessible while using your right hand.
My initial script is the following:
RControl & RShift::
{
send {LControl down}{tab}{LControl up}
return
}
It works fine, but while switching tabs in Visual Studio, for example, I cannot hold the CTRL key to keep switching tabs, I can only switch between 2 tabs.
Does anyone know if it is possible to achieve this kind of functionality with Autohotkey?
Thanks in advance.
You don't need the { } around the hotkey body. Hotkeys simply start with :: and end with return. Braces are only needed in functions afaik.
send {LControl down}{tab}{LControl up} could be expressed easier by send ^{tab} which is Ctrl+Tab. The tab-switch in VS also works with right RCtrl.
In either way, this does not work because of the send {ctrl up}. Ctrl needs to stay pressed down in order for the "Active files" window to stay open. Try:
RControl & RShift::send {RCtrl down}{tab}

Make Alt+Enter Send the End key, modifiers not working?

Pretty simple question, but I'm having issues. I tried this !Enter::Send, {End} It works great, but the problem I'm having is that I can't use other modifiers with it. Alt+Shift+Enter should act as Shift+End, and Alt+Ctrl+Enter should behave as Ctrl+End
I tried this too *!Enter::Send, {End} but it seems to ignore Ctrl and or Shift.
Hotkeys consume their events so the * is eating the Shift or Ctrl events.
* is useful when you want a range of hotkeys to all do the same thing.
*#c::Run Calc.exe ; Win+C, Shift+Win+C, Ctrl+Win+C, etc. all launch calc
The following should do what you want.
!Enter::^End
or
!Enter:: Send, {End}
+!Enter:: Send, +{End}
^!Enter:: Send, ^{End}

How to remap key in certain case and not remap in other case with autohotkey?

I want to remap alt+e when caps is on in autocad.
And when capslock is not on, alt+e should open menu edit.
I use script like this
<!e::
if(GetKeyState( "CAPSLOCK", "T" ))
{
SendInput erase{space}wp{space}
}
else
{
Send !e
}
When I turn on capslock, remap key is OK.
When I turn off capslockand alt+e, menu edit opened, but closed immediately.
Thanks.
You will want a $ at the beginning of your hotkey to prevent the endless loop that the !e in your else block will trigger. You will also want to add a Return at the end of the hotkey to prevent the script from continuing into what is below this hotkey.
$!e::
if GetKeyState( "CapsLock", "T" )
Sendinput, erase{space}wp{space}
else
Sendinput, !e
Return
(Brackets are only required when if/else blocks are more than one line.)
Beyond that, the likely issue is that it's an alt hotkey that is also set to send alt.
I say this is an issue because if you press and hold alt, it activates menus,
and then the script sends alt, which will be in conflict with that.
As Ricardo said, the ideal way to script this is with the #IF command (only included with AHK_L).
#If GetKeyState("CapsLock", "T") and WinActive("AutoCAD")
!e:: SendInput, erase{space}wp{space}
#If
Notice that you can add the WinActive() function to the #If command's expression.
Try it without that first, and also realize that the application's title needs to be exactly "AutoCAD" at all times for that to work. I would recommend finding AutoCad's ahk_class,
with AHK's window spy, instead of using the title.
If it still does not work, it is likely that AHK is sending faster than AutoCAD would like to receive.
Info on how to deal with that can be found here.
Try to change your else block to this:
Send, {ALTDOWN}e{ALTUP}
I do not rely on these symbols to send keystrokes in AutoHotKey.