You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AutoHotKey脚本按回车/小键盘回车无法获取复选框值求助

AutoHotKey: Enter/NumpadEnter Hotkeys Don't Capture Checkbox State

Problem Cause

The issue stems from the default behavior of a single-line Edit control: when you press Enter while focused on a single-line Edit, Windows automatically triggers the window's default button (your OK button). Since you also defined an Enter hotkey, these two events fire almost simultaneously, interfering with Gui, Submit's ability to correctly read the checkbox state—resulting in empty checkbox variables.

Solution

The simplest fix is to add the -Enter option to your Edit control to disable its default Enter behavior. This lets your hotkeys fire normally and correctly read all control states:

#Persistent
#SingleInstance Off
Gui, New, -MinimizeBox, % "Test"
Gui, Add, Edit, vUserInput w300 -Enter  ; Add -Enter to disable default Enter behavior
Gui, Add, Checkbox, vMyCheckbox1, % "Checkbox one"  ; Fixed typo: Ceckbox → Checkbox
Gui, Add, Checkbox, vMyCheckbox2, % "Checkbox two"
Gui, Add, Button, gOkButtonPress w50 h25 x80, % "OK"
Gui, Show, Center
return

Enter::
Gosub, OkButtonPress
return  ; Add return to properly end the hotkey code block

NumpadEnter::
Gosub, OkButtonPress
return  ; Add return here as well

OkButtonPress:
Gui, Submit
MsgBox, Meow! %MyCheckbox2%
ExitApp
return

Additional Improvements

  1. Fixed the typo in the first checkbox label (Ceckbox → Checkbox)
  2. Added return statements to the Enter and NumpadEnter hotkeys to follow AutoHotKey's code block conventions and avoid potential execution flow issues

Now when you run the script, clicking the OK button or pressing Enter/NumpadEnter will correctly display the second checkbox's state (0 or 1) in the message box.

内容的提问来源于stack exchange,提问作者user14430182

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 20:42:28