event.c
来自「适合KS8695X」· C语言 代码 · 共 1,116 行 · 第 1/3 页
C
1,116 行
*evt = EVT.evtq[evtID]; /* Return the event */
EVT.evtq[evtID].next = EVT.freeHead; /* and return to free list */
EVT.freeHead = evtID;
EVT.count--;
if (evt->what == EVT_MOUSEMOVE)
EVT.oldMove = -1;
if (evt->what == EVT_KEYREPEAT)
EVT.oldKey = -1;
if (evt->what == EVT_JOYMOVE)
EVT.oldJoyMove = -1;
_EVT_restoreInt(ps); /* enable interrupts */
if (evt->what & EVT_KEYEVT)
_EVT_maskKeyCode(evt);
}
/* If there is no event pending, check if we should generate an auto
* mouse down event if the mouse is still currently down.
*/
if (evt->what == EVT_NULLEVT && EVT.autoRepeat && (mask & EVT_MOUSEAUTO) && (EVT.downMouse.what & EVT_MOUSEDOWN)) {
ulong ticks = _EVT_getTicks();
if ((ticks - EVT.autoTicks) >= (EVT.autoRepeat + (EVT.firstAuto ? EVT.autoDelay : 0))) {
evt->what = EVT_MOUSEAUTO;
evt->message = EVT.downMouse.message;
evt->modifiers = EVT.downMouse.modifiers;
evt->where_x = EVT.autoMouse_x;
evt->where_y = EVT.autoMouse_y;
evt->relative_x = 0;
evt->relative_y = 0;
EVT.autoTicks = evt->when = ticks;
EVT.firstAuto = false;
}
}
return evt->what != EVT_NULLEVT;
}
/****************************************************************************
DESCRIPTION:
Installs a user supplied event filter callback for event handling.
HEADER:
event.h
PARAMETERS:
userEventFilter - Address of user supplied event filter callback
REMARKS:
This function allows the application programmer to install an event filter
callback for event handling. Once you install your callback, the MGL
event handling routines will call your callback with a pointer to the
new event that will be placed into the event queue. Your callback can the
modify the contents of the event before it is placed into the queue (for
instance adding custom information or perhaps high precision timing
information).
If your callback returns FALSE, the event will be ignore and will not be
posted to the event queue. You should always return true from your event
callback unless you plan to use the events immediately that they are
recieved.
Note: Your event callback may be called in response to a hardware
interrupt and will be executing in the context of the hardware
interrupt handler under MSDOS (ie: keyboard interrupt or mouse
interrupt). For this reason the code pages for the callback that
you register must be locked in memory with the PM_lockCodePages
function. You must also lock down any data pages that your function
needs to reference as well.
Note: You can also use this filter callback to process events at the
time they are activated by the user (ie: when the user hits the
key or moves the mouse), but make sure your code runs as fast as
possible as it will be executing inside the context of an interrupt
handler on some systems.
SEE ALSO:
EVT_getNext, EVT_peekNext
****************************************************************************/
void EVTAPI EVT_setUserEventFilter(
_EVT_userEventFilter filter)
{
EVT.userEventCallback = filter;
}
/****************************************************************************
DESCRIPTION:
Installs a user supplied event heartbeat callback function.
HEADER:
event.h
PARAMETERS:
callback - Address of user supplied event heartbeat callback
params - Parameters to pass to the event heartbeat function
REMARKS:
This function allows the application programmer to install an event heatbeat
function that gets called every time that EVT_getNext or EVT_peekNext
is called. This is primarily useful for simulating text mode cursors inside
event handling code when running in graphics modes as opposed to hardware
text modes.
SEE ALSO:
EVT_getNext, EVT_peekNext, EVT_getHeartBeatCallback
****************************************************************************/
void EVTAPI EVT_setHeartBeatCallback(
_EVT_heartBeatCallback callback,
void *params)
{
EVT.heartBeat = callback;
EVT.heartBeatParams = params;
}
/****************************************************************************
DESCRIPTION:
Returns the current user supplied event heartbeat callback function.
HEADER:
event.h
PARAMETERS:
callback - Place to store the address of user supplied event heartbeat callback
params - Place to store the parameters to pass to the event heartbeat function
REMARKS:
This function retrieves the current event heatbeat function that gets called
every time that EVT_getNext or EVT_peekNext is called.
SEE ALSO:
EVT_getNext, EVT_peekNext, EVT_setHeartBeatCallback
****************************************************************************/
void EVTAPI EVT_getHeartBeatCallback(
_EVT_heartBeatCallback *callback,
void **params)
{
*callback = EVT.heartBeat;
*params = EVT.heartBeatParams;
}
/****************************************************************************
DESCRIPTION:
Determines if a specified key is currently down.
PARAMETERS:
scanCode - Scan code to test
RETURNS:
True of the specified key is currently held down.
HEADER:
event.h
REMARKS:
This function determines if a specified key is currently down at the
time that the call is made. You simply need to pass in the scan code of
the key that you wish to test, and the MGL will tell you if it is currently
down or not. The MGL does this by keeping track of the up and down state
of all the keys.
****************************************************************************/
ibool EVTAPI EVT_isKeyDown(
uchar scanCode)
{
return _EVT_isKeyDown(scanCode);
}
/****************************************************************************
DESCRIPTION:
Set the mouse position for the event module
PARAMETERS:
x - X coordinate to move the mouse cursor position to
y - Y coordinate to move the mouse cursor position to
HEADER:
event.h
REMARKS:
This function moves the mouse cursor position for the event module to the
specified location.
SEE ALSO:
EVT_getMousePos
****************************************************************************/
void EVTAPI EVT_setMousePos(
int x,
int y)
{
EVT.mx = x;
EVT.my = y;
_EVT_setMousePos(&EVT.mx,&EVT.my);
EVT.mouseMove(EVT.mx,EVT.my);
}
/****************************************************************************
DESCRIPTION:
Returns the current mouse cursor location.
HEADER:
event.h
PARAMETERS:
x - Place to store value for mouse x coordinate (screen coordinates)
y - Place to store value for mouse y coordinate (screen coordinates)
REMARKS:
Obtains the current mouse cursor position in screen coordinates. Normally the
mouse cursor location is tracked using the mouse movement events that are
posted to the event queue when the mouse moves, however this routine
provides an alternative method of polling the mouse cursor location.
SEE ALSO:
EVT_setMousePos
****************************************************************************/
void EVTAPI EVT_getMousePos(
int *x,
int *y)
{
*x = EVT.mx;
*y = EVT.my;
}
/****************************************************************************
DESCRIPTION:
Returns the currently active code page for translation of keyboard characters.
HEADER:
event.h
RETURNS:
Pointer to the currently active code page translation table.
REMARKS:
This function is returns a pointer to the currently active code page
translation table. See EVT_setCodePage for more information.
SEE ALSO:
EVT_setCodePage
****************************************************************************/
codepage_t * EVTAPI EVT_getCodePage(void)
{
return EVT.codePage;
}
/****************************************************************************
DESCRIPTION:
Sets the currently active code page for translation of keyboard characters.
HEADER:
event.h
PARAMETERS:
page - New code page to make active
REMARKS:
This function is used to set a new code page translation table that is used
to translate virtual scan code values to ASCII characters for different
keyboard configurations. The default is usually US English, although if
possible the PM library will auto-detect the correct code page translation
for the target OS if OS services are available to determine what type of
keyboard is currently attached.
SEE ALSO:
EVT_getCodePage
****************************************************************************/
void EVTAPI EVT_setCodePage(
codepage_t *page)
{
EVT.codePage = page;
}
/* The following contains fake C prototypes and documentation for the
* macro functions in the event.h header file. These exist soley so
* that DocJet will correctly pull in the documentation for these functions.
*/
#ifdef INCLUDE_DOC_FUNCTIONS
/****************************************************************************
DESCRIPTION:
Macro to extract the ASCII code from a message.
PARAMETERS:
message - Message to extract ASCII code from
RETURNS:
ASCII code extracted from the message.
HEADER:
event.h
REMARKS:
Macro to extract the ASCII code from the message field of the event_t
structure. You pass the message field to the macro as the parameter and
the ASCII code is the result, for example:
event_t EVT.myEvent;
uchar code;
code = EVT_asciiCode(EVT.myEvent.message);
SEE ALSO:
EVT_scanCode, EVT_repeatCount
****************************************************************************/
uchar EVT_asciiCode(
ulong message);
/****************************************************************************
DESCRIPTION:
Macro to extract the keyboard scan code from a message.
HEADER:
event.h
PARAMETERS:
message - Message to extract scan code from
RETURNS:
Keyboard scan code extracted from the message.
REMARKS:
Macro to extract the keyboard scan code from the message field of the event
structure. You pass the message field to the macro as the parameter and
the scan code is the result, for example:
event_t EVT.myEvent;
uchar code;
code = EVT_scanCode(EVT.myEvent.message);
NOTE: Scan codes in the event library are not really hardware scan codes,
but rather virtual scan codes as generated by a low level keyboard
interface driver. All virtual scan code values are defined by the
EVT_scanCodesType enumeration, and will be identical across all
supports OS'es and platforms.
SEE ALSO:
EVT_asciiCode, EVT_repeatCount
****************************************************************************/
uchar EVT_scanCode(
ulong message);
/****************************************************************************
DESCRIPTION:
Macro to extract the repeat count from a message.
HEADER:
event.h
PARAMETERS:
message - Message to extract repeat count from
RETURNS:
Repeat count extracted from the message.
REMARKS:
Macro to extract the repeat count from the message field of the event
structure. The repeat count is the number of times that the key repeated
before there was another keyboard event to be place in the queue, and
allows the event handling code to avoid keyboard buffer overflow
conditions when a single key is held down by the user. If you are processing
a key repeat code, you will probably want to check this field to see how
many key repeats you should process for this message.
SEE ALSO:
EVT_asciiCode, EVT_repeatCount
****************************************************************************/
short EVT_repeatCount(
ulong message);
#endif /* DOC FUNCTIONS */
#if defined(__REALDOS__) || defined(__SMX32__)
/* {secret} */
void EVTAPI _EVT_cCodeEnd(void) {}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?