Skip to content

Commit 91d34f8

Browse files
committed
Set the console event handler before calling the main function
Rationale: Respond to console closing even if the main Python code has not finished yet.
1 parent fd5bf44 commit 91d34f8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ahkpy/Python.ahk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ Main() {
105105

106106
Py_DecRef(mainModule)
107107

108+
handleCtrlEventCB := RegisterCallback("HandleCtrlEvent", "Fast")
109+
DllCall("SetConsoleCtrlHandler", "Ptr", handleCtrlEventCB, "Int", true)
110+
108111
result := PyObject_CallObject(mainFunc, NULL)
109112
Py_DecRef(mainFunc)
110113
if (result == NULL) {
111114
PrintErrorOrExit()
112115
}
113116
Py_DecRef(result)
114117

115-
handleCtrlEventCB := RegisterCallback("HandleCtrlEvent", "Fast")
116-
DllCall("SetConsoleCtrlHandler", "Ptr", handleCtrlEventCB, "Int", true)
117-
118118
SetTimer, CheckSignals, 100
119119
}
120120

0 commit comments

Comments
 (0)