TraceLife

真正的幸福,在于对平淡生活的热爱……

导航

AutoIt 设置快捷键 -> HotKeySet

Posted on 2012-03-15 18:11  hallo  阅读(5648)  评论(0编辑  收藏  举报

AutoIt 设置快捷键 -> HotKeySet 


使用 AutoIt 编制 GUI 程序时,可以自定义快捷键。通常可以使用下面的代码:

 1 ; FILENAME HotKeySetDemo01.au3
2 ; PURPOSE: Hotkey demo
3 ; CREATED BY: @kysnail at
4 ; NOTE:
5 ;
6 ;
7 ; RESOURCE:
8 ;
9 ;
10 ; Press Esc to terminate script, Pause/Break to "pause"
11
12 ; Flag variable 'start/pause' the script
13 Global $Paused
14 ; Win Key + XXX
15 HotKeySet("#o", "WinHotKey")
16 ; CONTROL + ALT + XXX
17 HotKeySet("^!a", "CtlAltHotkey")
18 ; ALT + SHIFT + XXX
19 HotKeySet("!+a", "ShiAltHotKey")
20 ; {ESC}
21 HotKeySet("{ESC}", "Terminate")
22 ; {DOWN} -> Move down a menu
23 HotKeySet("{DOWN}", "MoveDownMenu")
24 ; Toggle the state
25 HotKeySet("{PAUSE}", "TogglePause")
26
27 ;;;; Body of program would go here ;;;;
28 While 1
29 Sleep(100)
30 WEnd
31 ;;;;;;;;
32
33 Func TogglePause()
34 $Paused = Not $Paused
35 While $Paused
36 Sleep(100)
37 ToolTip('Script is "Paused"', 2)
38 WEnd
39 ToolTip("")
40 EndFunc ;==>TogglePause
41
42 ; Terminate the demo
43 Func Terminate()
44 Exit 0
45 EndFunc ;==>Terminate
46
47 ; Move down a menu
48 Func MoveDownMenu()
49 MsgBox(4096, "MoveDownMenu Function", "You just move down a menu!")
50 EndFunc ;==>ShowMessage
51
52 ; Window Key + Key
53 Func WinHotKey()
54 MsgBox(0, "WinHotKey Function", "Actived by 'Win Key'")
55 EndFunc
56
57 ; Control + Alt + Key
58 Func CtlAltHotkey()
59 MsgBox(0, "CtlAltHotKey Function", "Actived by 'Ctrl + Alt + a'")
60 EndFunc ;==>CtlAltHotKey
61
62 ; Shift + Alt + Key
63 Func ShiAltHotKey()
64 MsgBox(0, "ShiAltHotKey Function", "Actived by 'Shift + Alt + a")
65 EndFunc

 

HotKeySet 函数的说明如下:

Sets a hotkey that calls a user function.

HotKeySet ( "key" [, "function"] )

根据定义的描述可知,HotKeySet 主要用来对用户自定义函数进行快捷设置。