我正在编写一个AutoHotkey脚本,我需要在其中处理控件事件。更具体地说,我有一个Edit和一个伙伴UpDown控件。当用户在编辑中按Enter键时我需要响应/处理事件,或者作为另一个示例需要响应由上/下控制引起的更改(用户没有用箭头键来上/下编辑值)或者点击那些小的向上/向下按钮。)
请告诉我如何处理控制事件,特别是有关Edit和UpDown控件的信息。
答案 0 :(得分:2)
Edit
控制文档:
http://ahkscript.org/docs/commands/GuiControls.htm#Edit
UpDown
控制文档:
http://ahkscript.org/docs/commands/GuiControls.htm#UpDown
OnMessage()
功能文档:
http://ahkscript.org/docs/commands/OnMessage.htm
示例实施:
Gui, Add, Edit, gEventHandler vMyEditControl
Gui, Add, UpDown, vMyUpDown Range1-10, 5
Gui, Show
OnMessage(WM_KEYUP:=0x101,"WM_KEYUP") ; WM_KEYUP msg, see http://msdn.microsoft.com/library/ms646281
return
GuiClose: ; exit app on 'guiclose' event
ExitApp
EventHandler: ; This label is launched when the contents of the edit has changed
GuiControlGet,value,,MyEditControl
MsgBox MyEditControl contains "%value%".
return
WM_KEYUP(wParam, lParam) { ; this function is launched on 'Key Up' event
if (wParam==0x0D) ; vk codes, see http://msdn.microsoft.com/library/dd375731
MsgBox Enter was pressed in MyEditControl.
}
答案 1 :(得分:1)
OR, 如果您在窗口上有多个Edit控件,并且您想要处理特定Edit控件的Enter press,那么请改进:
WM_KEYUP(wParam, lParam)
{
; vk codes, see http://msdn.microsoft.com/library/dd375731
IF (wParam==0x0D) ; 'Key Up' event for 'Enter'
{
GuiControlGet, FocusCtrl, FocusV
IF (FocusCtrl="MyEditControl") ; Focus is on MyEditControl Edit control
{
; when Enter is pressed and when MyEditControl has the keyboard focus
MsgBox Enter Presses on MyEditControl
}
}
}
特别感谢Joe DF的有用答案和精彩的文档。