Send Command Not Working When A Program Gets Run In AutoHotKey - autohotkey

i have some code which will if the user types something, it will type that to notepad, but it is only opening notepad and not typing.
InputBox, UserInput, NoteType, Enter something to type in notepad., , 640, 480
if ErrorLevel
ExitApp
else
Run, Notepad
Send, %UserInput%
Does anyone seem to have a solution for this?

There is a caveat when using if…else blocks in AHK, when executing multiple lines of code you have to use curly braces to enclose the block. Otherwise it just executes the first line in the block. Example:
InputBox, UserInput, NoteType, Enter something to type in notepad., , 640, 480
if ErrorLevel {
ExitApp
} else {
Run, Notepad
Send, %UserInput%
}
That should work now.

Related

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

My macro wont run more than once?

I have a simple macro, since i am very new to it. Literally started today. But i run this macro, and it runs once and stops. Why is that? Here it is:
q::
Send asdq
Esc::ExitApp
return
If someone could help me, I would really appreciate it.
Each hotkey you assign, that isn't a single line, requires a Return.
Since you have a definition of a Hotkey inside another, your second hotkey esc::exitapp is being executed when you press q and exiting your script.
Try:
q::Send, asdq
Esc::ExitApp
or:
q::
Send, asdq
Return
Esc::ExitApp
Edit:
q::
Loop
Send, asdq
Return
Esc:: ExitApp

Autohotkey and ExitApp: how to enable and disable ESC key to work just in a part of the script?

I have a very long script and I want to stop it with ESC key if it goes astray.
So I have put in the script this line:
Esc::ExitApp
But, of course, sometimes I have to press ESC key even when not running the script and when I need AutoHotkey, it's gone.
How do I tie ExitApp to ESC key just for a part of the script that's running?
You have to add ExitApp as a command in your script! It is a special kind of label, not a function. If the label doesn't exist in your script, you can't call it.
To make it exist, just add another line with the label on it. -->>**actually, I was wrong to say that. In the docs it gives the example that you can use simply Esc::ExitApp just like that to exit the running script ExitApp exists in the script even if you don't create it first because it's built into AutoHotkey. However, with your new code from your comment, you can use a custom label (which does have to exist in your script before you can call it):
Esc::goto DoSomething
DoSomething:
MsgBox, 4, , Are we exiting?
IfMsgBox, No
return ;after this return, the next line will not be called.
ExitApp ;as soon as this is called, the script ends completely and no more of the script will ever be called
return
this code is working:
Esc::goto ExitThisProgramQuestion
ExitThisProgramQuestion:
MsgBox, 4, , Are we exiting?
IfMsgBox, No
return
ExitApp
return

executing a script when at a specific classNN

How shouuld I tweak the following script so that the hotkey is activated not at ANY moment where I'm at the class shown (that is Outlook) but at a specific sub window ( the preview pane of the Inbox box (whose classNN is _WwG1 )) ?
#IfWinActive ahk_class rctrl_renwnd32
+!m::
ControlFocus, OutlookGrid1, ahk_class rctrl_renwnd32
if ErrorLevel ; i.e. it's not blank or zero.
MsgBox, You don't seem to be in context.
return
#IfWinActive
Make the hotkey look for active controls once it is activated. This way you can use the same hotkey for multiple commands, each command depending on the control. You can do this with several if/else statements to test for the subcontrols.
The hotkey only works in Outlook.
Each control has its own command
Each command is limited to that particular control
#ifwinactive, ahk_exe outlook.exe
{
+!m::
controlgetfocus, thiscontrol
if(thiscontrol = "_Wwg1"){
ControlFocus, OutlookGrid1, ahk_class rctrl_renwnd32
if ErrorLevel ; i.e. it's not blank or zero.
MsgBox, You seem to focused on %thiscontrol%
}else if(thiscontrol = "_Wsg2){
msgbox, you've discovered the second control!
}
return
}

script opens document but not with hotkey

I'm creating a script to open and run with a program that has no help files but comes with a huge PDF manual. There is no way to open it from the program, so I have set up a command to open it. The command opens the PDF when run on its own, but when I assign a hotkey, it does not work. What very basic information am I missing?
thanks,
Ellen
SetTitleMatchMode, 2
runwait C:\Program Files\FontLab\TypeTool3\TTool3.exe, , max
IfWinExist TypeTool 3
Return
ExitApp
Return
#ifWinActive, TypeTool 3
$wheeldown::wheelup
$wheelup::wheeldown
F1::
Run, C:\Documents and Settings\Ellen\My Documents\TypeTool3WinMan.pdf
Return
#ifWinActive
Do you have a Return before your #IfWinActive statement? If not then during startup the script will run every line until it hits the first Return, which seems to be all the way to the end for you. So also place a return after your Run, C:..... command
And oh.. Are you sure about that weird long ahk_class? It could be correct but it looks strange and if this is just a littlebit off, your hotkey would never work, so try it first with the #IfWinActive line commented out.
SetTitleMatchMode, 2
;All the stuff you want to run at startup....
Return
#ifWinActive, (part of) the window name here e.g. Excel
$wheeldown::wheelup
$wheelup::wheeldown
F1::
Run, C:\Documents and Settings\Ellen\My Documents\TypeTool3WinMan.pdf
Return
#ifWinActive