Making AHK script in Notepad ++ - autohotkey

Im trying to make an ahk script to try and simplify a one time use script. Pretty much im running over 1000 commands in a game one after one another .Currently I have something like this. I have all the commands in a single text file just not with any ahk coding.
.waypointadd 1 100234 40 -469
.waypointadd 2 99549 34 5
.waypointadd 3 100615 37 -160
.waypointadd 4 100817 27 -457
.waypointadd 5 100503.5 10.5 -647.5
.waypointadd 6 100494.5 10.5 -625.5
This goes on for a while. Im new to using expressions and such and am pretty much trying to make it to press enter, type the command, then press enter, then go to the next one. I obviously cant do this manually. I have tried using some basic replace expressions and stuff but not really sure how to do this.
In the end i would want it to look like this
send {enter}
send (command 1)
send {enter}
send {enter}
send (command 2)
send {enter}

you could bind it to a key like....
1::
loop, 1 {
send {enter}
send (command 1)
send {enter}
send {enter}
send (command 2)
send {enter}
}
or make a function when you a press a key. lmk if this helps or not
doSomething() {
send {enter}
send (command 1)
send {enter}
send {enter}
send (command 2)
send {enter}
}
1::
doSomething()

You could store all the commands in your clipboard (CTRL+C them) and then loop through all of them:
Loop, Parse, Commands, `n, `r ;split by linefeed, ignore carriage return
{
SendInput, % A_LoopField "{Enter 2}"
Sleep, 1000 ;however long you need
}
Loads of ways to get the commands into your script, I just went with loading them from your clipboard, should be pretty easy convenient to just copy the block of commands you want and then starting the script.
Then there's a parsing loop.
And then SendInput is used to send the current command follow by two presses of Enter.
Alternatively, if your game supports pasting from clipboard, it would be nice to just load your clipboard with whatever you want to send, and then sending a CTRL+V.
If the code with SendInput is going too fast, you can try switching over to normal Send and maybe even using SetKeyDelay to add even more delay between the keypresses.

Related

ctrl+s not being sent in autohotkey script

i.e. hitting ctrl+s should activate ctrl+s...the below does not work. Neither does the simpler
SendInput, ^s. Goal is to have ctrl+s save current doc and then load another via more code, the saving part never works tho. The bad code, depending on where i put sleep or no sleep, either returns s or shift s (in 1 code editor anyways) or nothing. I basically want a hotkey that mimics itself.
F4::ExitApp
<^s::
send, {lctrl down}
SLEEP 300
SEND s
SLEEP 300
SEND {lctrl up}
return
I would think that the issue your program is running into is that having the ^s send another ^s inside of itself is creating an infinite recursive loop in which nothing is ever able to run past the place you invoke ^s. To prevent this, we can use the $ modifier as so:
$<^s::
SendInput ^s
return
From the relevant section of the Modifier section of the docs:
This is usually only necessary if the script uses the Send command to
send the keys that comprise the hotkey itself, which might otherwise
cause it to trigger itself. The $ prefix forces the keyboard hook to
be used to implement this hotkey, which as a side-effect prevents the
Send command from triggering it. The $ prefix is equivalent to having
specified #UseHook somewhere above the definition of this hotkey.
Edit: it seems to work fine for me even if I remove the $ modifier. Testing the following code shows me there appears to be no problems regarding code execution before, after, or during the SendInput statement.
<^s::
MsgBox no
SendInput, ^s
MsgBox yes
return
Maybe check your version or installation of AHK?

Autohotkey loop down key/folder-files

I want to add +1 to {Down} after starting the next loop
F8::
stop := 0
Loop, 13
{
Run, "C:\Users\USER\Desktop\docs"
Send {Home}
Sleep 1000
Send {Down} ;Here i want to add +1 after loop start again
Sleep 2000
Send {Enter}
Sleep 2000
Send !{F11}
Sleep 2000
Send {F5}
Sleep 2000
Send !{f4}
Sleep 2000
}until Stop
return
F9::Stop := 1
If someone has a different solution how to open files one by one and perform a given action and add it in a loop, please give me some suggestions.
OK i know the answer
Send, {Down %A_index%}
What i want to do. So I want to Open folder with some texts files (MS Word) and open first one, klick macro (alt+f11) then start macro (f5) and klick (alt + f4) to close macro window and next (alt+f4) to close word window then klick twice enter to accept save changes, then start loop again with next document (loop time = x documents in folder). But im done right now ;p
Anyway if u have any other idea how do things like this in future u can tell ;p
PS Add+1 dostn work ;p

Automatic translation

im really new to all this and i was trying to make an Autohotkey for translation. i was digging for some time looking for examples that only confused me more, even if the code looked simple, i didn't understand half of it.
So, what I'm trying to do is: select a paragraph and replace it automatically with its translation.
i was hooping it to be somenthing as simple as CTRJ + C, Translate, CTRL + V, but i can't find the command to go to google translate or somenthing similar, it's not on the autohotkey help file so i'm guessing i don't have libraries?
I'm at my wits end, please help.
You came to the right place. Check out AutoHotKey for sure.
First, how to do it by hand? Those are the steps for ahk. So, lets say you have a paragraph of text selected. You will hit the ahk shortcut and that shortcut will:
first ahk figures out what window its in (using WinGetActiveTitle) and then sends the keystrokes Ctrl+c to copy the selection ("send, ^c" and "Clipwait"), then
ahk can access the clipboard containing the text, do a string manipulation or regex to replace all spaces with the html escape sequence %20 (eg, transtext := StrReplace(Clipboard, " ", "%20")) and
construct a URL to do the Google Translate, something like (where sl is source language and tl is translation language, and text is what you want translated): transurl := "https://translate.google.com/#view=home&op=translate&sl=en&tl=es&text=" . transtext
AHK runs that url and opens a browser window showing result (run % transurl).
This part sucks. Now, you need to use a mouse click at a location (or maybe you can find a controlsend or a combination of keystrokes moving the cursor with tabs and such) to land on the "Copy translation" button. Or how bout you do it manually (try sleep, 8000 to wait while you hit the button)
then have ahk close the window (optionally, or you just do it by hand during the sleep time) and
ahk switches back to the application with the original selected paragraph (WinActivate or do it yourself) and
send ctrl+v to paste the translated text over the original (send ^v).
A starter pack of AHK code (edited per user comments):
WinGetActiveTitle, activewin
Clipboard =
SendInput, ^c
ClipWait
transtext := StrReplace(Clipboard, " ", "%20")
transurl := "https://translate.google.com/#view=home&op=translate&sl=en&tl=es&text=" . transtext
Run, % transurl
Sleep, 6000 ; adjust to taste.
SendEvent, {tab 10} ; adjust to taste.
Sleep 1000
SendInput, {enter}
Sleep, 1000
SendInput, ^{F4}
WinActivate, activewin
sleep, 1000
SendInput, ^v
Try it and let us know how else to help.
OKOK, first of all, thank you all, the script works just fine now. I'm able to copy, translate and paste any text now. Only a few questions lingering.
1) i'm not sure i get what the step number 5 is suppose to do. whatever it is, it works so i don't touch it.
2) is there a way to reset google.translate so it dosent open a new window every time? that could save a lot of time.
3) this one doesn't have a chance, but i ask anyway. Is there a way to not open google chrome at all? because i know that u can translate from excel automatically. (i know that if it is possible will be super hard)
This is the code i ended with:
^a::
clipboard := ""
sendinput, ^c
ClipWait [,,Waitforanydata]
transtext := StrReplace(Clipboard, " ", "%20")
transurl := "https://translate.google.com/#view=home&op=translate&sl=en&tl=es&text=" .
transtext
run % transurl
Sleep, 4000
SendEvent, {tab 9}
SendEvent, {enter}
Winactivate, NAME.pdf - PROGRAM
sendinput, ^v

autohotkey Restricting a script to only run a designated program

I use Teraterm for my terminal program. My issue is I cannot make my script run only when I am in the teraterm program. Is there a way to make it pop into teraterm if I am in a different app?
The script works great please share it to anyone who uses teraterm.
We always use the same server ip that shows up in the window title it contains 10.155.3.8. That text is always in the title.
How do I make it execute only in teraterm. I know this is an incredibly simple question but I have spend days looking around any help would be greatly appreciated.
If you have any basic tutorial sites I would greatly appreciate it.
I am a programming neophyte.
::ttwa:: ; change teraterm window name to current device or state.
SetTitleMatchMode, 2 ;// allow partial window title matches
#IfWinActive, 156.99.121.173, 156.99.121.173
send !e
sleep 10
send s
send {enter 100}
sleep 100
Send {click 3}
send !s
sleep 10
Send w
sleep 10
send %clipboard%
sleep 100
;send {backspace}
sleep 10
send {enter}
send !e s {enter}
send {enter 10}
Clipboard :=
return
There are several methods:
assign a hotkey which you would press to initiate the script:
^+F1::
.... send stuff
....
return
wait for the teraterm window to appear (WinWait) or become active (WinWaitActive):
winwait, teraterm ; change to the actual window qualifications
.... send stuff
....
return
run teraterm from your script, so you'll run the script icon instead of running teraterm directly:
run teraterm ; change to the actual path
winwait, teraterm ; change to the actual window qualifications
.... send stuff
....
return
Well. To me it looks like you have the answer already in your script.
From the Docs here: #IfWinActive
Creates context-sensitive hotkeys and hotstrings. Such hotkeys perform
a different action (or none at all) depending on the type of window
that is active or exists.
You simply have your script executing that requirement, out of order in which in needs to be.
SetTitleMatchMode, 2
#ifWinActive, 156.99.121.173, 156.99.121.173 ;Assuming this is correct
::ttwa:: ; change teraterm window name to current device or state.
send !e
sleep 10
send s
send {enter 100}
sleep 100
Send {click 3}
send !s
sleep 10
Send w
sleep 10
send %clipboard%
sleep 100
;send {backspace}
sleep 10
send {enter}
send !e s {enter}
send {enter 10}
Clipboard :=
return
As for recommendations on furthering your understanding of AutoHotkey, I strongly suggest starting with the official Tutorial.

Holding control, shift and v, using only one key

I am using lightroom for this hotkey. I dont know why is this doesn't work for me.
::{control}{sleep 5}{shift}{sleep 5}v
And Alt+F+↓(5x) then Enter.
And Alt+F+↓(5x) then Enter.
I don't know what you mean by that, because I can't see anything like that in your script. So I will just ignore it and do what the thread title and your script says/implies.
The following script will simulate pressing Ctrl+Shift+V when you press the A key
SetKeyDelay, 5 ;wait 5 milliseconds between every keystroke
a::^+v
About your comment, I guess I know what you are on to, try this:
SetKeyDelay, 5 ;wait 5 milliseconds between every keystroke
2::
SendInput, !f
Sleep, 50
SendInput, {Down}{Down}{Down}{Down}{Down}{Enter}
Return