2 /* ========================== Module _Evt =========================== */
9 #include "pywintoolbox.h"
12 #include "pymactoolbox.h"
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
23 #ifdef WITHOUT_FRAMEWORKS
26 #include <Carbon/Carbon.h>
30 static PyObject
*Evt_Error
;
32 static PyObject
*Evt_GetMouse(PyObject
*_self
, PyObject
*_args
)
34 PyObject
*_res
= NULL
;
37 PyMac_PRECHECK(GetMouse
);
39 if (!PyArg_ParseTuple(_args
, ""))
42 _res
= Py_BuildValue("O&",
43 PyMac_BuildPoint
, mouseLoc
);
47 static PyObject
*Evt_Button(PyObject
*_self
, PyObject
*_args
)
49 PyObject
*_res
= NULL
;
52 PyMac_PRECHECK(Button
);
54 if (!PyArg_ParseTuple(_args
, ""))
57 _res
= Py_BuildValue("b",
62 static PyObject
*Evt_StillDown(PyObject
*_self
, PyObject
*_args
)
64 PyObject
*_res
= NULL
;
67 PyMac_PRECHECK(StillDown
);
69 if (!PyArg_ParseTuple(_args
, ""))
72 _res
= Py_BuildValue("b",
77 static PyObject
*Evt_WaitMouseUp(PyObject
*_self
, PyObject
*_args
)
79 PyObject
*_res
= NULL
;
82 PyMac_PRECHECK(WaitMouseUp
);
84 if (!PyArg_ParseTuple(_args
, ""))
87 _res
= Py_BuildValue("b",
92 static PyObject
*Evt_GetCaretTime(PyObject
*_self
, PyObject
*_args
)
94 PyObject
*_res
= NULL
;
97 PyMac_PRECHECK(GetCaretTime
);
99 if (!PyArg_ParseTuple(_args
, ""))
101 _rv
= GetCaretTime();
102 _res
= Py_BuildValue("l",
107 static PyObject
*Evt_GetKeys(PyObject
*_self
, PyObject
*_args
)
109 PyObject
*_res
= NULL
;
110 KeyMap theKeys__out__
;
112 PyMac_PRECHECK(GetKeys
);
114 if (!PyArg_ParseTuple(_args
, ""))
116 GetKeys(theKeys__out__
);
117 _res
= Py_BuildValue("s#",
118 (char *)&theKeys__out__
, (int)sizeof(KeyMap
));
122 static PyObject
*Evt_GetDblTime(PyObject
*_self
, PyObject
*_args
)
124 PyObject
*_res
= NULL
;
127 PyMac_PRECHECK(GetDblTime
);
129 if (!PyArg_ParseTuple(_args
, ""))
132 _res
= Py_BuildValue("l",
137 static PyObject
*Evt_SetEventMask(PyObject
*_self
, PyObject
*_args
)
139 PyObject
*_res
= NULL
;
142 PyMac_PRECHECK(SetEventMask
);
144 if (!PyArg_ParseTuple(_args
, "H",
153 static PyObject
*Evt_GetNextEvent(PyObject
*_self
, PyObject
*_args
)
155 PyObject
*_res
= NULL
;
158 EventRecord theEvent
;
160 PyMac_PRECHECK(GetNextEvent
);
162 if (!PyArg_ParseTuple(_args
, "H",
165 _rv
= GetNextEvent(eventMask
,
167 _res
= Py_BuildValue("bO&",
169 PyMac_BuildEventRecord
, &theEvent
);
173 static PyObject
*Evt_EventAvail(PyObject
*_self
, PyObject
*_args
)
175 PyObject
*_res
= NULL
;
178 EventRecord theEvent
;
180 PyMac_PRECHECK(EventAvail
);
182 if (!PyArg_ParseTuple(_args
, "H",
185 _rv
= EventAvail(eventMask
,
187 _res
= Py_BuildValue("bO&",
189 PyMac_BuildEventRecord
, &theEvent
);
193 static PyObject
*Evt_PostEvent(PyObject
*_self
, PyObject
*_args
)
195 PyObject
*_res
= NULL
;
200 PyMac_PRECHECK(PostEvent
);
202 if (!PyArg_ParseTuple(_args
, "Hl",
206 _err
= PostEvent(eventNum
,
208 if (_err
!= noErr
) return PyMac_Error(_err
);
214 static PyObject
*Evt_FlushEvents(PyObject
*_self
, PyObject
*_args
)
216 PyObject
*_res
= NULL
;
220 PyMac_PRECHECK(FlushEvents
);
222 if (!PyArg_ParseTuple(_args
, "HH",
226 FlushEvents(whichMask
,
233 static PyObject
*Evt_GetGlobalMouse(PyObject
*_self
, PyObject
*_args
)
235 PyObject
*_res
= NULL
;
237 #ifndef GetGlobalMouse
238 PyMac_PRECHECK(GetGlobalMouse
);
240 if (!PyArg_ParseTuple(_args
, ""))
242 GetGlobalMouse(&globalMouse
);
243 _res
= Py_BuildValue("O&",
244 PyMac_BuildPoint
, globalMouse
);
248 static PyObject
*Evt_GetCurrentKeyModifiers(PyObject
*_self
, PyObject
*_args
)
250 PyObject
*_res
= NULL
;
252 #ifndef GetCurrentKeyModifiers
253 PyMac_PRECHECK(GetCurrentKeyModifiers
);
255 if (!PyArg_ParseTuple(_args
, ""))
257 _rv
= GetCurrentKeyModifiers();
258 _res
= Py_BuildValue("l",
263 static PyObject
*Evt_CheckEventQueueForUserCancel(PyObject
*_self
, PyObject
*_args
)
265 PyObject
*_res
= NULL
;
267 #ifndef CheckEventQueueForUserCancel
268 PyMac_PRECHECK(CheckEventQueueForUserCancel
);
270 if (!PyArg_ParseTuple(_args
, ""))
272 _rv
= CheckEventQueueForUserCancel();
273 _res
= Py_BuildValue("b",
278 static PyObject
*Evt_KeyScript(PyObject
*_self
, PyObject
*_args
)
280 PyObject
*_res
= NULL
;
283 PyMac_PRECHECK(KeyScript
);
285 if (!PyArg_ParseTuple(_args
, "h",
294 static PyObject
*Evt_IsCmdChar(PyObject
*_self
, PyObject
*_args
)
296 PyObject
*_res
= NULL
;
301 PyMac_PRECHECK(IsCmdChar
);
303 if (!PyArg_ParseTuple(_args
, "O&h",
304 PyMac_GetEventRecord
, &event
,
307 _rv
= IsCmdChar(&event
,
309 _res
= Py_BuildValue("b",
314 static PyObject
*Evt_LMGetKeyThresh(PyObject
*_self
, PyObject
*_args
)
316 PyObject
*_res
= NULL
;
318 #ifndef LMGetKeyThresh
319 PyMac_PRECHECK(LMGetKeyThresh
);
321 if (!PyArg_ParseTuple(_args
, ""))
323 _rv
= LMGetKeyThresh();
324 _res
= Py_BuildValue("h",
329 static PyObject
*Evt_LMSetKeyThresh(PyObject
*_self
, PyObject
*_args
)
331 PyObject
*_res
= NULL
;
333 #ifndef LMSetKeyThresh
334 PyMac_PRECHECK(LMSetKeyThresh
);
336 if (!PyArg_ParseTuple(_args
, "h",
339 LMSetKeyThresh(value
);
345 static PyObject
*Evt_LMGetKeyRepThresh(PyObject
*_self
, PyObject
*_args
)
347 PyObject
*_res
= NULL
;
349 #ifndef LMGetKeyRepThresh
350 PyMac_PRECHECK(LMGetKeyRepThresh
);
352 if (!PyArg_ParseTuple(_args
, ""))
354 _rv
= LMGetKeyRepThresh();
355 _res
= Py_BuildValue("h",
360 static PyObject
*Evt_LMSetKeyRepThresh(PyObject
*_self
, PyObject
*_args
)
362 PyObject
*_res
= NULL
;
364 #ifndef LMSetKeyRepThresh
365 PyMac_PRECHECK(LMSetKeyRepThresh
);
367 if (!PyArg_ParseTuple(_args
, "h",
370 LMSetKeyRepThresh(value
);
376 static PyObject
*Evt_LMGetKbdLast(PyObject
*_self
, PyObject
*_args
)
378 PyObject
*_res
= NULL
;
381 PyMac_PRECHECK(LMGetKbdLast
);
383 if (!PyArg_ParseTuple(_args
, ""))
385 _rv
= LMGetKbdLast();
386 _res
= Py_BuildValue("b",
391 static PyObject
*Evt_LMSetKbdLast(PyObject
*_self
, PyObject
*_args
)
393 PyObject
*_res
= NULL
;
396 PyMac_PRECHECK(LMSetKbdLast
);
398 if (!PyArg_ParseTuple(_args
, "b",
407 static PyObject
*Evt_LMGetKbdType(PyObject
*_self
, PyObject
*_args
)
409 PyObject
*_res
= NULL
;
412 PyMac_PRECHECK(LMGetKbdType
);
414 if (!PyArg_ParseTuple(_args
, ""))
416 _rv
= LMGetKbdType();
417 _res
= Py_BuildValue("b",
422 static PyObject
*Evt_LMSetKbdType(PyObject
*_self
, PyObject
*_args
)
424 PyObject
*_res
= NULL
;
427 PyMac_PRECHECK(LMSetKbdType
);
429 if (!PyArg_ParseTuple(_args
, "b",
438 static PyObject
*Evt_TickCount(PyObject
*_self
, PyObject
*_args
)
440 PyObject
*_res
= NULL
;
443 PyMac_PRECHECK(TickCount
);
445 if (!PyArg_ParseTuple(_args
, ""))
448 _res
= Py_BuildValue("l",
453 static PyObject
*Evt_WaitNextEvent(PyObject
*_self
, PyObject
*_args
)
455 PyObject
*_res
= NULL
;
459 EventRecord theEvent
;
461 Handle mouseregion
= (Handle
)0;
463 if (!PyArg_ParseTuple(_args
, "Hl|O&",
466 OptResObj_Convert
, &mouseregion
))
468 _rv
= WaitNextEvent(eventMask
,
471 (RgnHandle
)mouseregion
);
472 _res
= Py_BuildValue("bO&",
474 PyMac_BuildEventRecord
, &theEvent
);
479 static PyMethodDef Evt_methods
[] = {
480 {"GetMouse", (PyCFunction
)Evt_GetMouse
, 1,
481 PyDoc_STR("() -> (Point mouseLoc)")},
482 {"Button", (PyCFunction
)Evt_Button
, 1,
483 PyDoc_STR("() -> (Boolean _rv)")},
484 {"StillDown", (PyCFunction
)Evt_StillDown
, 1,
485 PyDoc_STR("() -> (Boolean _rv)")},
486 {"WaitMouseUp", (PyCFunction
)Evt_WaitMouseUp
, 1,
487 PyDoc_STR("() -> (Boolean _rv)")},
488 {"GetCaretTime", (PyCFunction
)Evt_GetCaretTime
, 1,
489 PyDoc_STR("() -> (UInt32 _rv)")},
490 {"GetKeys", (PyCFunction
)Evt_GetKeys
, 1,
491 PyDoc_STR("() -> (KeyMap theKeys)")},
492 {"GetDblTime", (PyCFunction
)Evt_GetDblTime
, 1,
493 PyDoc_STR("() -> (UInt32 _rv)")},
494 {"SetEventMask", (PyCFunction
)Evt_SetEventMask
, 1,
495 PyDoc_STR("(EventMask value) -> None")},
496 {"GetNextEvent", (PyCFunction
)Evt_GetNextEvent
, 1,
497 PyDoc_STR("(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)")},
498 {"EventAvail", (PyCFunction
)Evt_EventAvail
, 1,
499 PyDoc_STR("(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)")},
500 {"PostEvent", (PyCFunction
)Evt_PostEvent
, 1,
501 PyDoc_STR("(EventKind eventNum, UInt32 eventMsg) -> None")},
502 {"FlushEvents", (PyCFunction
)Evt_FlushEvents
, 1,
503 PyDoc_STR("(EventMask whichMask, EventMask stopMask) -> None")},
504 {"GetGlobalMouse", (PyCFunction
)Evt_GetGlobalMouse
, 1,
505 PyDoc_STR("() -> (Point globalMouse)")},
506 {"GetCurrentKeyModifiers", (PyCFunction
)Evt_GetCurrentKeyModifiers
, 1,
507 PyDoc_STR("() -> (UInt32 _rv)")},
508 {"CheckEventQueueForUserCancel", (PyCFunction
)Evt_CheckEventQueueForUserCancel
, 1,
509 PyDoc_STR("() -> (Boolean _rv)")},
510 {"KeyScript", (PyCFunction
)Evt_KeyScript
, 1,
511 PyDoc_STR("(short code) -> None")},
512 {"IsCmdChar", (PyCFunction
)Evt_IsCmdChar
, 1,
513 PyDoc_STR("(EventRecord event, short test) -> (Boolean _rv)")},
514 {"LMGetKeyThresh", (PyCFunction
)Evt_LMGetKeyThresh
, 1,
515 PyDoc_STR("() -> (SInt16 _rv)")},
516 {"LMSetKeyThresh", (PyCFunction
)Evt_LMSetKeyThresh
, 1,
517 PyDoc_STR("(SInt16 value) -> None")},
518 {"LMGetKeyRepThresh", (PyCFunction
)Evt_LMGetKeyRepThresh
, 1,
519 PyDoc_STR("() -> (SInt16 _rv)")},
520 {"LMSetKeyRepThresh", (PyCFunction
)Evt_LMSetKeyRepThresh
, 1,
521 PyDoc_STR("(SInt16 value) -> None")},
522 {"LMGetKbdLast", (PyCFunction
)Evt_LMGetKbdLast
, 1,
523 PyDoc_STR("() -> (UInt8 _rv)")},
524 {"LMSetKbdLast", (PyCFunction
)Evt_LMSetKbdLast
, 1,
525 PyDoc_STR("(UInt8 value) -> None")},
526 {"LMGetKbdType", (PyCFunction
)Evt_LMGetKbdType
, 1,
527 PyDoc_STR("() -> (UInt8 _rv)")},
528 {"LMSetKbdType", (PyCFunction
)Evt_LMSetKbdType
, 1,
529 PyDoc_STR("(UInt8 value) -> None")},
530 {"TickCount", (PyCFunction
)Evt_TickCount
, 1,
531 PyDoc_STR("() -> (UInt32 _rv)")},
532 {"WaitNextEvent", (PyCFunction
)Evt_WaitNextEvent
, 1,
533 PyDoc_STR("(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)")},
548 m
= Py_InitModule("_Evt", Evt_methods
);
549 d
= PyModule_GetDict(m
);
550 Evt_Error
= PyMac_GetOSErrException();
551 if (Evt_Error
== NULL
||
552 PyDict_SetItemString(d
, "Error", Evt_Error
) != 0)
556 /* ======================== End module _Evt ========================= */