mirror of
https://github.com/PCSX2/pcsx2.git
synced 2026-09-09 14:22:58 +02:00
I'll put up a wiki soon which covers new compilation features and stuff, like how to re-enable revision tagging, and how you can direct compiled exe/dlls to be copied to any destination of your choice (yay!) -- plus many other compiling tips (if I can remember them all! >_<) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@581 96395faa-99c1-11dd-bbfe-3dabce05a288
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
// This is undoubtedly completely unnecessary.
|
|
#include "KeyboardQueue.h"
|
|
|
|
static int numQueuedEvents = 0;
|
|
static keyEvent queuedEvents[20];
|
|
|
|
// What MS calls a single process Mutex. Faster, supposedly.
|
|
// More importantly, can be abbreviated, amusingly, as cSection.
|
|
static CRITICAL_SECTION cSection;
|
|
static int csInitialized = 0;
|
|
|
|
void QueueKeyEvent(int key, int event) {
|
|
if (!csInitialized) {
|
|
csInitialized = 1;
|
|
InitializeCriticalSection(&cSection);
|
|
}
|
|
EnterCriticalSection(&cSection);
|
|
if (numQueuedEvents >= 15) {
|
|
// Generally shouldn't happen.
|
|
for (int i=0; i<15; i++) {
|
|
queuedEvents[i] = queuedEvents[i+5];
|
|
}
|
|
numQueuedEvents = 15;
|
|
}
|
|
int index = numQueuedEvents;
|
|
// Move escape to top of queue. May do something
|
|
// with shift/ctrl/alt and F-keys, later.
|
|
if (event == KEYPRESS && key == VK_ESCAPE) {
|
|
while (index) {
|
|
queuedEvents[index-1] = queuedEvents[index];
|
|
index--;
|
|
}
|
|
}
|
|
queuedEvents[index].key = key;
|
|
queuedEvents[index].evt = event;
|
|
numQueuedEvents ++;
|
|
LeaveCriticalSection(&cSection);
|
|
}
|
|
|
|
int GetQueuedKeyEvent(keyEvent *event) {
|
|
int out = 0;
|
|
if (numQueuedEvents) {
|
|
EnterCriticalSection(&cSection);
|
|
// Shouldn't be 0, but just in case...
|
|
if (numQueuedEvents) {
|
|
*event = queuedEvents[0];
|
|
numQueuedEvents--;
|
|
out = 1;
|
|
for (int i=0; i<numQueuedEvents; i++) {
|
|
queuedEvents[i] = queuedEvents[i+1];
|
|
}
|
|
}
|
|
LeaveCriticalSection(&cSection);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
void ClearKeyQueue() {
|
|
if (numQueuedEvents) {
|
|
numQueuedEvents = 0;
|
|
}
|
|
if (csInitialized) {
|
|
DeleteCriticalSection(&cSection);
|
|
csInitialized = 0;
|
|
}
|
|
}
|