clear key event buffer
clear key event buffer
- Subject: clear key event buffer
- From: Dingcai Cao <email@hidden>
- Date: Fri, 14 Jan 2005 17:14:13 -0600
Dear all,
I am developing an Objective-C application for a visual experiment,
which utilizes a Gamepad to give response to different stimuli. It is
possible, however, that subjects press a button multiple times for a
given stimulus. In this situation, the code I have written processes
the first key event and carries over the rest key events to the
following stimuli, which messes thing up. What I want is to process the
first event and clear the rest. Is there anyway I can clear the rest
key events while keep the first one? I am attaching my code in the
following.
Many thanks in advance.
Dingcai Cao
===========================================
Here is my code.
/* GamePad.h */
#import <Cocoa/Cocoa.h>
//Gamepad key definitions
#define CONTROL_SHIFT 0x60000
#define QUIT 0x6000c
#define BUTTON_1 0x60012
#define BUTTON_2 0x60013
#define BUTTON_3 0x60014
#define BUTTON_4 0x60015
#define BUTTON_5 0x60017
#define BUTTON_6 0x60016
#define BUTTON_7 0x6001a
#define BUTTON_8 0x6001c
#define BUTTON_9 0x60019
#define BUTTON_10 0x6001d
#define BUTTON_LEFT 0x260056
#define BUTTON_RIGHT 0x260058
#define BUTTON_TOP 0x26005b
#define BUTTON_BOTTOM 0x260054
/*Gamepad.m*/
@interface GamePad : NSObject
{
NSDate *distantPast ;
NSEvent *event;
NSEventType eventType;
unsigned int eventFlags;
unsigned int eventKey;
}
-(void)setEvent;
-(int)handleEvent;
@end
#import "GamePad.h"
@implementation GamePad
-(void) setEvent {
distantPast= [[NSDate distantPast] retain];
event = [NSApp
nextEventMatchingMask: NSAnyEventMask
untilDate: distantPast
inMode: NSDefaultRunLoopMode
dequeue: YES ];
}
-(int) handleEvent
{
if (event)
{
eventType = [event type];
eventFlags = [event modifierFlags];
eventKey = [event keyCode];
switch (eventType) {
case NSKeyDown:
if ((eventKey + eventFlags) == QUIT) exit(1);
printf("%0x\n", eventKey+ eventFlags);
return eventKey+ eventFlags;
break;
case QUIT:
exit(1);
break;
default:
return 0;
}
}
return 0;
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden