150ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
250ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen/* ========================== Module _Evt =========================== */
350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen#include "Python.h"
550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
65640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussoren#ifndef __LP64__
750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen#include "pymactoolbox.h"
1050ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
1150ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen/* Macro to test whether a weak-loaded CFM function exists */
1250ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
13ca56dd4767617a2f5e946130de4beb06442a5cd5Martin Panter        PyErr_SetString(PyExc_NotImplementedError, \
14ca56dd4767617a2f5e946130de4beb06442a5cd5Martin Panter            "Not available in this shared library/OS version"); \
15ca56dd4767617a2f5e946130de4beb06442a5cd5Martin Panter        return NULL; \
1650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen    }} while(0)
1750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
1850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
1950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen#include <Carbon/Carbon.h>
2050ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
2150ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
2250ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_Error;
2350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
2450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_GetMouse(PyObject *_self, PyObject *_args)
2550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
26c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
27c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Point mouseLoc;
289d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef GetMouse
29c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(GetMouse);
309d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
31c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
32c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
33c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    GetMouse(&mouseLoc);
34c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("O&",
35c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         PyMac_BuildPoint, mouseLoc);
36c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
3750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
3850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
3950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_Button(PyObject *_self, PyObject *_args)
4050ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
41c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
42c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Boolean _rv;
439d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef Button
44c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(Button);
459d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
46c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
47c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
48c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = Button();
49c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("b",
50c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
51c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
5250ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
5350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
5450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_StillDown(PyObject *_self, PyObject *_args)
5550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
56c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
57c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Boolean _rv;
589d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef StillDown
59c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(StillDown);
609d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
61c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
62c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
63c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = StillDown();
64c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("b",
65c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
66c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
6750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
6850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
6950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_WaitMouseUp(PyObject *_self, PyObject *_args)
7050ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
71c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
72c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Boolean _rv;
739d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef WaitMouseUp
74c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(WaitMouseUp);
759d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
76c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
77c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
78c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = WaitMouseUp();
79c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("b",
80c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
81c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
8250ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
8350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
8450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_GetCaretTime(PyObject *_self, PyObject *_args)
8550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
86c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
87c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt32 _rv;
889d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef GetCaretTime
89c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(GetCaretTime);
909d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
91c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
92c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
93c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = GetCaretTime();
94c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("l",
95c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
96c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
9750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
9850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
9950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_GetKeys(PyObject *_self, PyObject *_args)
10050ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
101c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
102c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    KeyMap theKeys__out__;
1039d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef GetKeys
104c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(GetKeys);
1059d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
106c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
107c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
108c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    GetKeys(theKeys__out__);
109c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("s#",
110c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         (char *)&theKeys__out__, (int)sizeof(KeyMap));
111c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
11250ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
11350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
11450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_GetDblTime(PyObject *_self, PyObject *_args)
11550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
116c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
117c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt32 _rv;
1189d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef GetDblTime
119c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(GetDblTime);
1209d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
121c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
122c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
123c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = GetDblTime();
124c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("l",
125c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
126c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
12750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
12850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
12950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_SetEventMask(PyObject *_self, PyObject *_args)
13050ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
131c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
132c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventMask value;
1339d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef SetEventMask
134c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(SetEventMask);
1359d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
136c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "H",
137c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &value))
138c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
139c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    SetEventMask(value);
140c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Py_INCREF(Py_None);
141c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_None;
142c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
14350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
14450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
14550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_GetNextEvent(PyObject *_self, PyObject *_args)
14650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
147c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
148c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Boolean _rv;
149c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventMask eventMask;
150c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventRecord theEvent;
1519d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef GetNextEvent
152c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(GetNextEvent);
1539d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
154c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "H",
155c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &eventMask))
156c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
157c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = GetNextEvent(eventMask,
158c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                       &theEvent);
159c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("bO&",
160c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv,
161c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         PyMac_BuildEventRecord, &theEvent);
162c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
16350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
16450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
16550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_EventAvail(PyObject *_self, PyObject *_args)
16650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
167c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
168c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Boolean _rv;
169c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventMask eventMask;
170c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventRecord theEvent;
1719d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef EventAvail
172c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(EventAvail);
1739d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
174c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "H",
175c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &eventMask))
176c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
177c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = EventAvail(eventMask,
178c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                     &theEvent);
179c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("bO&",
180c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv,
181c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         PyMac_BuildEventRecord, &theEvent);
182c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
18350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
18450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
18550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_PostEvent(PyObject *_self, PyObject *_args)
18650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
187c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
188c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    OSErr _err;
189c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventKind eventNum;
190c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt32 eventMsg;
1919d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef PostEvent
192c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(PostEvent);
1939d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
194c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "Hl",
195c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &eventNum,
196c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &eventMsg))
197c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
198c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _err = PostEvent(eventNum,
199c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                     eventMsg);
200c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (_err != noErr) return PyMac_Error(_err);
201c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Py_INCREF(Py_None);
202c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_None;
203c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
20450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
20550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
20650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_FlushEvents(PyObject *_self, PyObject *_args)
20750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
208c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
209c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventMask whichMask;
210c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventMask stopMask;
2119d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef FlushEvents
212c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(FlushEvents);
2139d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
214c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "HH",
215c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &whichMask,
216c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &stopMask))
217c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
218c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    FlushEvents(whichMask,
219c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                stopMask);
220c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Py_INCREF(Py_None);
221c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_None;
222c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
22350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
22450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
22550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_GetGlobalMouse(PyObject *_self, PyObject *_args)
22650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
227c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
228c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Point globalMouse;
2299d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef GetGlobalMouse
230c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(GetGlobalMouse);
2319d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
232c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
233c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
234c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    GetGlobalMouse(&globalMouse);
235c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("O&",
236c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         PyMac_BuildPoint, globalMouse);
237c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
23850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
23950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
24050ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_GetCurrentKeyModifiers(PyObject *_self, PyObject *_args)
24150ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
242c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
243c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt32 _rv;
2449d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef GetCurrentKeyModifiers
245c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(GetCurrentKeyModifiers);
2469d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
247c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
248c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
249c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = GetCurrentKeyModifiers();
250c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("l",
251c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
252c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
25350ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
25450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
25550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_CheckEventQueueForUserCancel(PyObject *_self, PyObject *_args)
25650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
257c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
258c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Boolean _rv;
2599d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef CheckEventQueueForUserCancel
260c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(CheckEventQueueForUserCancel);
2619d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
262c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
263c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
264c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = CheckEventQueueForUserCancel();
265c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("b",
266c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
267c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
26850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
26950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
2702168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_KeyScript(PyObject *_self, PyObject *_args)
2712168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
272c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
273c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    short code;
2749d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef KeyScript
275c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(KeyScript);
2769d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
277c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "h",
278c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &code))
279c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
280c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    KeyScript(code);
281c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Py_INCREF(Py_None);
282c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_None;
283c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
2842168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
2852168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
2862168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_IsCmdChar(PyObject *_self, PyObject *_args)
2872168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
288c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
289c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Boolean _rv;
290c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventRecord event;
291c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    short test;
2929d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef IsCmdChar
293c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(IsCmdChar);
2949d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
295c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "O&h",
296c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          PyMac_GetEventRecord, &event,
297c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &test))
298c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
299c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = IsCmdChar(&event,
300c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                    test);
301c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("b",
302c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
303c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
3042168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
3052168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
3062168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_LMGetKeyThresh(PyObject *_self, PyObject *_args)
3072168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
308c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
309c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    SInt16 _rv;
3109d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef LMGetKeyThresh
311c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(LMGetKeyThresh);
3129d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
313c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
314c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
315c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = LMGetKeyThresh();
316c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("h",
317c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
318c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
3192168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
3202168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
3212168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_LMSetKeyThresh(PyObject *_self, PyObject *_args)
3222168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
323c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
324c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    SInt16 value;
3259d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef LMSetKeyThresh
326c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(LMSetKeyThresh);
3279d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
328c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "h",
329c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &value))
330c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
331c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    LMSetKeyThresh(value);
332c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Py_INCREF(Py_None);
333c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_None;
334c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
3352168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
3362168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
3372168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_LMGetKeyRepThresh(PyObject *_self, PyObject *_args)
3382168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
339c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
340c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    SInt16 _rv;
3419d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef LMGetKeyRepThresh
342c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(LMGetKeyRepThresh);
3439d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
344c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
345c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
346c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = LMGetKeyRepThresh();
347c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("h",
348c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
349c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
3502168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
3512168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
3522168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_LMSetKeyRepThresh(PyObject *_self, PyObject *_args)
3532168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
354c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
355c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    SInt16 value;
3569d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef LMSetKeyRepThresh
357c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(LMSetKeyRepThresh);
3589d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
359c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "h",
360c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &value))
361c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
362c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    LMSetKeyRepThresh(value);
363c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Py_INCREF(Py_None);
364c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_None;
365c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
3662168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
3672168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
3682168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_LMGetKbdLast(PyObject *_self, PyObject *_args)
3692168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
370c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
371c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt8 _rv;
3729d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef LMGetKbdLast
373c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(LMGetKbdLast);
3749d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
375c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
376c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
377c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = LMGetKbdLast();
378c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("b",
379c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
380c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
3812168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
3822168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
3832168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_LMSetKbdLast(PyObject *_self, PyObject *_args)
3842168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
385c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
386c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt8 value;
3879d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef LMSetKbdLast
388c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(LMSetKbdLast);
3899d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
390c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "b",
391c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &value))
392c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
393c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    LMSetKbdLast(value);
394c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Py_INCREF(Py_None);
395c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_None;
396c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
3972168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
3982168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
3992168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_LMGetKbdType(PyObject *_self, PyObject *_args)
4002168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
401c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
402c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt8 _rv;
4039d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef LMGetKbdType
404c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(LMGetKbdType);
4059d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
406c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
407c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
408c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = LMGetKbdType();
409c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("b",
410c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
411c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
4122168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
4132168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
4142168e9d602cffbb6975a11353707a921455c05f7Jack Jansenstatic PyObject *Evt_LMSetKbdType(PyObject *_self, PyObject *_args)
4152168e9d602cffbb6975a11353707a921455c05f7Jack Jansen{
416c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
417c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt8 value;
4189d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef LMSetKbdType
419c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(LMSetKbdType);
4209d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
421c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "b",
422c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &value))
423c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
424c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    LMSetKbdType(value);
425c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Py_INCREF(Py_None);
426c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_None;
427c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
4282168e9d602cffbb6975a11353707a921455c05f7Jack Jansen}
4292168e9d602cffbb6975a11353707a921455c05f7Jack Jansen
430ec982e2739f6d7992d530c0940965f6eeb73a467Jack Jansenstatic PyObject *Evt_TickCount(PyObject *_self, PyObject *_args)
431ec982e2739f6d7992d530c0940965f6eeb73a467Jack Jansen{
432c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
433c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt32 _rv;
4349d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#ifndef TickCount
435c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyMac_PRECHECK(TickCount);
4369d79990ac725830134b7a9147f18297a0e6da5dbJack Jansen#endif
437c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, ""))
438c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
439c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = TickCount();
440c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("l",
441c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv);
442c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
443ec982e2739f6d7992d530c0940965f6eeb73a467Jack Jansen}
444ec982e2739f6d7992d530c0940965f6eeb73a467Jack Jansen
44550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyObject *Evt_WaitNextEvent(PyObject *_self, PyObject *_args)
44650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
447c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *_res = NULL;
448c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
449c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Boolean _rv;
450c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventMask eventMask;
451c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    EventRecord theEvent;
452c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    UInt32 sleep;
453c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Handle mouseregion = (Handle)0;
454c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
455c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (!PyArg_ParseTuple(_args, "Hl|O&",
456c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &eventMask,
457c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          &sleep,
458c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          OptResObj_Convert, &mouseregion))
459c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return NULL;
460c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _rv = WaitNextEvent(eventMask,
461c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                        &theEvent,
462c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                        sleep,
463c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                        (RgnHandle)mouseregion);
464c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    _res = Py_BuildValue("bO&",
465c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         _rv,
466c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                         PyMac_BuildEventRecord, &theEvent);
467c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    return _res;
46850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
46950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
47050ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
47150ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenstatic PyMethodDef Evt_methods[] = {
472c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
473c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (Point mouseLoc)")},
474c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"Button", (PyCFunction)Evt_Button, 1,
475c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (Boolean _rv)")},
476c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"StillDown", (PyCFunction)Evt_StillDown, 1,
477c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (Boolean _rv)")},
478c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
479c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (Boolean _rv)")},
480c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1,
481c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (UInt32 _rv)")},
482c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
483c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (KeyMap theKeys)")},
484c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1,
485c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (UInt32 _rv)")},
486c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1,
487c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(EventMask value) -> None")},
488c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
489c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)")},
490c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
491c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)")},
492c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
493c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(EventKind eventNum, UInt32 eventMsg) -> None")},
494c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
495c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(EventMask whichMask, EventMask stopMask) -> None")},
496c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"GetGlobalMouse", (PyCFunction)Evt_GetGlobalMouse, 1,
497c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (Point globalMouse)")},
498c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"GetCurrentKeyModifiers", (PyCFunction)Evt_GetCurrentKeyModifiers, 1,
499c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (UInt32 _rv)")},
500c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"CheckEventQueueForUserCancel", (PyCFunction)Evt_CheckEventQueueForUserCancel, 1,
501c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (Boolean _rv)")},
502c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"KeyScript", (PyCFunction)Evt_KeyScript, 1,
503c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(short code) -> None")},
504c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"IsCmdChar", (PyCFunction)Evt_IsCmdChar, 1,
505c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(EventRecord event, short test) -> (Boolean _rv)")},
506c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"LMGetKeyThresh", (PyCFunction)Evt_LMGetKeyThresh, 1,
507c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (SInt16 _rv)")},
508c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"LMSetKeyThresh", (PyCFunction)Evt_LMSetKeyThresh, 1,
509c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(SInt16 value) -> None")},
510c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"LMGetKeyRepThresh", (PyCFunction)Evt_LMGetKeyRepThresh, 1,
511c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (SInt16 _rv)")},
512c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"LMSetKeyRepThresh", (PyCFunction)Evt_LMSetKeyRepThresh, 1,
513c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(SInt16 value) -> None")},
514c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"LMGetKbdLast", (PyCFunction)Evt_LMGetKbdLast, 1,
515c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (UInt8 _rv)")},
516c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"LMSetKbdLast", (PyCFunction)Evt_LMSetKbdLast, 1,
517c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(UInt8 value) -> None")},
518c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"LMGetKbdType", (PyCFunction)Evt_LMGetKbdType, 1,
519c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (UInt8 _rv)")},
520c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"LMSetKbdType", (PyCFunction)Evt_LMSetKbdType, 1,
521c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(UInt8 value) -> None")},
522c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"TickCount", (PyCFunction)Evt_TickCount, 1,
523c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("() -> (UInt32 _rv)")},
524c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
525c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou     PyDoc_STR("(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)")},
526c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {NULL, NULL, 0}
52750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen};
52850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
52950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
5305640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussoren#else /* __LP64__ */
5315640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussoren
5325640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussorenstatic PyMethodDef Evt_methods[] = {
533c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    {NULL, NULL, 0}
5345640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussoren};
5355640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussoren#endif /* __LP64__ */
53650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
53750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
53850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansenvoid init_Evt(void)
53950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen{
540c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *m;
5415640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussoren#ifndef __LP64__
542c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    PyObject *d;
5435640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussoren#endif /* __LP64__ */
54450ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
54550ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
54650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
54750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
548c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    m = Py_InitModule("_Evt", Evt_methods);
5495640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussoren#ifndef __LP64__
550c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    d = PyModule_GetDict(m);
551c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    Evt_Error = PyMac_GetOSErrException();
552c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    if (Evt_Error == NULL ||
553c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        PyDict_SetItemString(d, "Error", Evt_Error) != 0)
554c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        return;
5555640ce2f1edc0148ee14fd3daeb7ac700700bb71Ronald Oussoren#endif /* __LP64__ */
55650ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen}
55750ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
55850ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen/* ======================== End module _Evt ========================= */
55950ecb0ad835480e6a3446613ceeffa78a7bd2de3Jack Jansen
560