So far our hotkeys have been very simple, one-line affairs, but sometimes you need more than that. In those instances, you can create multi-line actions that you want to occur when your hotkey is triggered. This requires a slightly different syntax. hotkey:: Basically, as you can see, it starts out the same way with the hotkey followed by two colons. Then, however, you break to a new line and write your first action, followed by however many you want, and it ends with "return" (which signifies that the hotkey is done executing). So let's put it into practice. The following keyboard shortcut, Windows-t, will automatically empty the Recycle Bin when I press it. When it's finished, it will show me a message telling me that the trash has been taken out. #t:: In the hotkey created above, I used AutoHotkey's FileRecycleEmpty command, which takes the drive letter where the bin is located as a parameter. I also used another new concept: the MsgBox command, which displays the text after the command in a window. As you can see, I used it to confirm that the command was run and the trash was taken out. Restrict Your Hotkey to a Specific Application Sometimes you want to create a hotkey that will only be applicable to one specific application. In those cases, you need to use the #IfWinActive directive. To use it, you need to place #IfWinActive WindowType (where WindowType is the window or app you want the shortcut to apply to) followed by the hotkey, then followed again by #IfWinActive #IfWinActive ahk_class MozillaUIWindowClass So let's dive in and examine this bit of code. First, you'll notice the ahk_class MozillaUIWindowClass bit. That may seem intimidating, but all it does is tell AutoHotkey that this shortcut will only work when a program using the MozillaUIWindowClass (like Firefox or Thunderbird) is active. You can grab the ahk_class using the AutoIt3 Window Spy, which you'll find in your AutoHotkey install directory. Just run it and click on the window you want to restrict a hotkey to grab the window class and that's a good starting point. Next, we've used the Send command, which sends literal keystrokes to your window. The first one I sent was Send, {Alt}t, meaning that the bracketed text, Alt, indicates a modifier (again, go to the Send page for a closer look at modifiers)). If you were to press Alt-t in Firefox right now, you'll notice that the Tools menu drops down. Then I sent the command Sleep 100, which tells the script to wait 100 milliseconds before going to the next command. I do this just to make sure the computer has time to react to my first command and the Tools menu is open. Then I sent the "o" key to select Options from the Tools drop-down menu. Finally, I ended the hotkey with the return followed by #IfWinActive to ensure any other hotkeys beyond this one aren't limited just to Firefox or Thunderbird (unless that's what you wanted).
Do one thing
Do more things...
return
FileRecycleEmpty, C:\
MsgBox, The trash has been taken out.
return
without any WindowType (so that all following hotkeys won't be restricted to one window or application). In the example below, I've set the Windows-o hotkey to open the Options in Firefox.
#o::
Send {Alt}t
Sleep 100
Send o
return
#IfWinActive
Wednesday, March 12, 2008
Creating More Complex Hotkeys
·
Labels: General
Subscribe to:
Post Comments (Atom)
Check out my new blog:
Translation
Recent Posts
Who's Online?
Pageviews Today
About Me
嗨,我是花,居住在印度兴奋的Windows,Linux中国的外籍人士和所有高科技的东西
Receive updates for free
Labels
- Tips 'n' Tricks (171)
- Windows Vista (105)
- Website/ Blogging (91)
- General (88)
- Windows XP (84)
- Internet (59)
- Windows 7 (54)
- Software (43)
- Mobile-Tips and Tricks (35)
- Review (28)
- Security (28)
- SEO Tools (25)
- iPhone (17)
- Linux (14)
- Windows Mobile (14)
- mac (13)
- Mobile (12)
- MS Office (7)
- Hardware (6)
- Windows 98 (6)
- Zune (6)
- Games (4)
- Mobile Reviews (3)
- Disclaimer (2)
Blog Archive
- June (2)
- May (2)
- August (2)
- July (1)
- June (1)
- May (2)
- April (4)
- March (4)
- February (1)
- December (2)
- November (1)
- November (1)
- June (2)
- May (28)
- April (54)
- March (83)
- February (60)
- January (57)
- December (48)
- November (17)
- October (28)
- September (22)
- August (19)
- July (34)
- June (59)
- May (1)
- April (5)
- March (22)
- February (5)
- January (31)
0 comments:
Post a Comment