Вы находитесь на странице: 1из 6

10/03/13

AutoHotkey FAQ

Language Syntax
When are quotation marks used with commands and their parameters? When exactly are variable names enclosed in percent signs? When should percent signs and commas be escaped?

Common Tasks
Why do some lines in my script never execute? Why is the Run command unable to launch my game or program? How can the output of a command line operation be retrieved? How can a script close, pause, or suspend other script(s)? How can a repeating action be stopped without exiting the script? How can performance be improved for games or at other times when the CPU is under heavy load? How can context sensitive help for AutoHotkey commands be used in any editor? How to detect when a web page is finished loading? How can dates and times be compared or manipulated? Why don't Hotstrings, Send, and MouseClick work in certain games? How can Winamp be controlled even when it isn't active? How can MsgBox's button names be changed?

Hotkeys, Hotstrings, and Remapping


How do I put my hotkeys and hotstrings into effect automatically every time I start my PC? I'm having trouble getting my mouse buttons working as hotkeys. Any advice? How can tab and space be defined as hotkeys? How can keys or mouse buttons be remapped so that they become different keys? How can a hotkey or hotstring be made exclusive to certain program(s)? In other words, I want a certain key to act as it normally does except when a specific window is active. How can a prefix key be made to perform its native function rather than doing nothing? How can the built-in Windows shortcut keys, such as Win+U (Utility Manager) and Win+R (Run), be changed or disabled? My keypad has a special 000 key. Is it possible to turn it into a hotkey?

Language Syntax

When are quotation marks used with commands and their parameters?
Double quotes (") have special meaning only within expressions. In all other places, they are treated literally as if they were normal characters. However, when a script launches a program or document, the operating system usually requires quotes around any command-line parameter that contains spaces, such as in this example: Run, Notepad.exe "C:\M y Documents\Address List.txt"

When exactly are variable names enclosed in percent signs?


Variable names are always enclosed in percent signs except in cases illustrated in bold below: 1) In parameters that are input or output variables: StringLen, OutputVar, InputVar 2) On the left side of an assignment: Var = 123abc 3) On the left side of traditional (non-expression) if-statements: If Var1 < %Var2% 4) Everywhere in expressions. For example: If (Var1 <> Var2) Var1 := Var2 + 100
www.autohotkey.com/docs/FAQ.htm 1/6

10/03/13

AutoHotkey FAQ

When should percent signs and commas be escaped?


Literal percent signs must be escaped by preceding them with an accent/backtick. For example: MsgBox The current percentage is 25`%. Literal commas must also be escaped (`,) except when used in MsgBox or the last parameter of any command (in which case the accent is permitted but not necessary). When commas or percent signs are enclosed in quotes within an expression, the accent is permitted but not necessary. For example: Var := "15%"

Common Tasks

Why do some lines in my script never execute?


Any lines you want to execute immediately when the script starts should appear at the top of the script, prior to the first hotkey, hotstring, or Return. For details, see auto-execute section. Also, a hotkey that executes more than one line must list its first line beneath the hotkey, not on the same line. For example: # s p a c e : : ;W i n + S p a c e b a r R u nN o t e p a d W i n W a i t A c t i v eU n t i t l e d-N o t e p a d W i n M a x i m i z e r e t u r n

Why is the Run command unable to launch my game or program?


Some programs need to be started in their own directories (when in doubt, it is usually best to do so). For example: Run, %A_ProgramFiles%\Some Application\App.exe, %A_ProgramFiles%\Some Application

How can the output of a command line operation be retrieved?


Testing shows that due to file caching, a temporary file can be very fast for relatively small outputs. In fact, if the file is deleted immediately after use, it often does not actually get written to disk. For example: R u n W a i t% c o m s p e c %/ cd i r>C : \ M yT e m pF i l e . t x t F i l e R e a d ,V a r T o C o n t a i n C o n t e n t s ,C : \ M yT e m pF i l e . t x t F i l e D e l e t e ,C : \ M yT e m pF i l e . t x t To avoid using a temporary file (especially if the output is large), consider using CmdRet. Alternatively, there is a small freeware utility cb.zip (4 KB) that captures up to 512 KB of output from a command or program. The text is captured to the clipboard, which a script can access via the clipboard variable. For example: R u n W a i t% c o m s p e c %/ cd i r|c b . e x e M s g B o x% c l i p b o a r d %

How can a script close, pause, or suspend other script(s)?


First, here is an example that closes another script: D e t e c t H i d d e n W i n d o w sO n ;A l l o w sas c r i p t ' sh i d d e nm a i nw i n d o wt ob ed e t e c t e d . S e t T i t l e M a t c h M o d e2 ;A v o i d st h en e e dt os p e c i f yt h ef u l lp a t ho ft h ef i l eb e l o w . W i n C l o s eS c r i p t ' sF i l eN a m e . a h k-A u t o H o t k e y ;U p d a t et h i st or e f l e c tt h es c r i p t ' sn a m e( c a s es e n s i t i v e ) . To suspend or pause another script, replace the last line above with one of these: P o s t M e s s a g e ,0 x 1 1 1 ,6 5 3 0 5 , , ,S c r i p t ' sF i l eN a m e . a h k-A u t o H o t k e y ;S u s p e n d . P o s t M e s s a g e ,0 x 1 1 1 ,6 5 3 0 6 , , ,S c r i p t ' sF i l eN a m e . a h k-A u t o H o t k e y ;P a u s e .

www.autohotkey.com/docs/FAQ.htm

2/6

10/03/13

AutoHotkey FAQ

How can a repeating action be stopped without exiting the script?


To pause or resume the entire script at the press of a key, assign a hotkey to the Pause command as in this example: ^ ! p : : P a u s e ;P r e s sC t r l + A l t + Pt op a u s e .P r e s si ta g a i nt or e s u m e . To stop an action that is repeating inside a Loop, consider the following working example, which is a hotkey that both starts and stops its own repeating action. In other words, pressing the hotkey once will start the Loop. Pressing the same hotkey again will stop it. # M a x T h r e a d s P e r H o t k e y3 #z:: ; W i n + Zh o t k e y( c h a n g et h i sh o t k e yt os u i ty o u rp r e f e r e n c e s ) . # M a x T h r e a d s P e r H o t k e y1 i fK e e p W i n Z R u n n i n g ;T h i sm e a n sa nu n d e r l y i n gt h r e a di sa l r e a d yr u n n i n gt h el o o pb e l o w . { K e e p W i n Z R u n n i n g: =f a l s e ;S i g n a lt h a tt h r e a d ' sl o o pt os t o p . r e t u r n ;E n dt h i st h r e a ds ot h a tt h eo n eu n d e r n e a t hw i l lr e s u m ea n ds e et h ec h a n g em a d eb yt h el i n ea b o v e . } ;O t h e r w i s e : K e e p W i n Z R u n n i n g: =t r u e L o o p { ;T h en e x tf o u rl i n e sa r et h ea c t i o ny o uw a n tt or e p e a t( u p d a t et h e mt os u i ty o u rp r e f e r e n c e s ) : T o o l T i p ,P r e s sW i n Za g a i nt os t o pt h i sf r o mf l a s h i n g . S l e e p1 0 0 0 T o o l T i p S l e e p1 0 0 0 ;B u tl e a v et h er e s tb e l o wu n c h a n g e d . i fn o tK e e p W i n Z R u n n i n g ;T h eu s e rs i g n a l e dt h el o o pt os t o pb yp r e s s i n gW i n Za g a i n . b r e a k ;B r e a ko u to ft h i sl o o p . } K e e p W i n Z R u n n i n g: =f a l s e ;R e s e ti np r e p a r a t i o nf o rt h en e x tp r e s so ft h i sh o t k e y . r e t u r n

How can performance be improved for games or at other times when the CPU is under heavy load?
If a script's Hotkeys, Clicks, or Sends are noticeably slower than normal while the CPU is under heavy load, raising the script's process-priority may help. To do this, include the following line near the top of the script: Process, Priority, , High

How can context sensitive help for AutoHotkey commands be used in any editor?
Rajat created this script.

How to detect when a web page is finished loading?


With Internet Explorer, perhaps the most reliable method is to use DllCall and COM as demonstrated at www.autohotkey.com/forum/topic19256.html. On a related note, the contents of the address bar and status bar can be retrieved as demonstrated at www.autohotkey.com/forum/topic19255.html. Older, less reliable method: The technique in the following example will work with M S Internet Explorer for most pages. A similar technique might work in other browsers: R u n ,w w w . y a h o o . c o m M o u s e M o v e ,0 ,0 ;P r e v e n t st h es t a t u sb a rf r o ms h o w i n gam o u s e h o v e rl i n ki n s t e a do f" D o n e " . W i n W a i t ,Y a h o o !W i n A c t i v a t e
www.autohotkey.com/docs/FAQ.htm 3/6

10/03/13

AutoHotkey FAQ

S t a t u s B a r W a i t ,D o n e ,3 0 i fE r r o r L e v e l M s g B o xT h ew a i tt i m e do u to rt h ew i n d o ww a sc l o s e d . e l s e M s g B o xT h ep a g ei sd o n el o a d i n g .

How can dates and times be compared or manipulated?


The EnvAdd command can add or subtract a quantity of days, hours, minutes, or seconds to a time-string that is in the YYYYMMDDHH24MISS format. The following example subtracts 7 days from the specified time: EnvAdd, VarContainingTimestamp, -7, days To determine the amount of time between two dates or times, see EnvSub, which gives an example. Also, the built-in variable A_Now contains the current local time. Finally, there are several built-in date/time variables, as well as the FormatTime command to create a custom date/time string.

Why do Hotstrings, Send, and Click have no effect in certain games?


Some games use DirectInput exclusively. As a side-effect, they might ignore all simulated keystrokes and mouse clicks. To work around this, try one of the following (or a combination): Use SendPlay via: 1) the SendPlay command; 2) using SendMode Play; and/or 3) the hotstring option SP. Increase SetKeyDelay. For example: SetKeyDelay, 0, 50 SetKeyDelay, 0, 50, Play Try ControlSend, which might work in cases where the other Send modes fail.

How can Winamp be controlled even when it isn't active?


See Automating Winamp.

How can MsgBox's button names be changed?


Here is an example.

Hotkeys, Hotstrings, and Remapping

How do I put my hotkeys and hotstrings into effect automatically every time I start my PC?
There is a folder in the Start M enu called Startup. If you put a shortcut to your script in that folder, the script will launch automatically every time you start your PC. To create a shortcut: 1. Find the script file, select it, and press Control-C. 2. Right-click the Start button (typically at the lower left corner of the screen) and choose "Explore All Users". 3. Navigate to the Startup folder inside the Programs folder. 4. From the menu bar, choose Edit -> Paste Shortcut. The shortcut to the script should now be in the Startup folder.

I'm having trouble getting my mouse buttons working as hotkeys. Any advice?
Note that mouse hotkeys are not currently possible on Windows 95/98/M e. On other operating systems, the left and right mouse buttons should be assignable normally (for example, "#LButton::" is the Win+LeftButton hotkey). Similarly, the middle button and the turning of the mouse wheel should be assignable normally
www.autohotkey.com/docs/FAQ.htm 4/6

10/03/13

AutoHotkey FAQ

except on mice whose drivers directly control those buttons. The fourth button (XButton1) and the fifth button (XButton2) might be assignable if your mouse driver allows their clicks to be seen by the system. If they cannot be seen -- or if your mouse has more than five buttons that you want to use -- you can try configuring the software that came with the mouse (sometimes accessible in the Control Panel or Start M enu) to send a keystroke whenever you press one of these buttons. Such a keystroke can then be defined as a hotkey in a script. For example, if you configure the fourth button to send Control+F1, you can then indirectly configure that button as a hotkey by using ^F1:: in a script. If you have a five-button mouse whose fourth and fifth buttons cannot be seen, you can try changing your mouse driver to the default driver included with the OS. This assumes there is such a driver for your particular mouse and that you can live without the features provided by your mouse's custom software.

How can Tab and Space be defined as hotkeys?


Use the names of the keys (Tab and Space) rather than their characters. For example, #Space is Win+Space and ^!Tab is Control+Alt+Tab.

How can keys or mouse buttons be remapped so that they become different keys?
This is described on the remapping page.

How can a hotkey or hotstring be made exclusive to certain program(s)? In other words, I want a certain key to act as it normally does except when a specific window is active.
The preferred method is #IfWinActive. For example: # I f W i n A c t i v e ,a h k _ c l a s sN o t e p a d ^ a : : M s g B o xY o up r e s s e dC o n t r o l Aw h i l eN o t e p a di sa c t i v e . Windows 95/98/M e: Although the above method works, pressing Control-A in a window other than Notepad will do nothing at all (not even its native function). To work around this, use: $ ^ a : : S e n d^ a ;T h i sh o t k e ym u s tb el i s t e d first o nW i n d o w s9 x .T h e$p r e f i xa l l o w si tt o" s e n di t s e l f " . # I f W i n A c t i v e ,a h k _ c l a s sN o t e p a d ^ a : : M s g B o xY o up r e s s e dC o n t r o l Aw h i l eN o t e p a di sa c t i v e .

How can a prefix key be made to perform its native function rather than doing nothing?
Consider the following example, which makes Numpad0 into a prefix key: N u m p a d 0&N u m p a d 1 : : M s g B o x ,Y o up r e s s e dN u m p a d 1w h i l eh o l d i n gd o w nN u m p a d 0 . Now, to make Numpad0 send a real Numpad0 keystroke whenever it wasn't used to launch a hotkey such as the above, add the following hotkey: $ N u m p a d 0 : : S e n d ,{ N u m p a d 0 } The $ prefix is needed to prevent a warning dialog about an infinite loop (since the hotkey "sends itself"). In addition, the above action occurs at the time the key is released.

How can the built-in Windows shortcut keys, such as Win+U (Utility Manager) and Win+R (Run), be changed or disabled?
www.autohotkey.com/docs/FAQ.htm 5/6

10/03/13

AutoHotkey FAQ

Here are some examples.

My keypad has a special 000 key. Is it possible to turn it into a hotkey?


You can, but only if you're running Windows NT, 2000, XP, or beyond. This example script makes the 000 key into an equals key. You can change the action by replacing the "Send, =" line with line(s) of your choice. Home | Download | Documentation | Changelog | Support | Forum | Wiki

www.autohotkey.com/docs/FAQ.htm

6/6

Вам также может понравиться