Game Development Reference
In-Depth Information
self.isKeyboardEnabled = YES;
The callback methods to receive keyboard events are defined in the CCKey-
boardEventDelegate protocol as follows:
-(BOOL) ccKeyDown:(NSEvent*)event
{
CCLOG(@"key pressed: %@", event.characters);
}
-(BOOL) ccKeyUp:(NSEvent*)event
{
CCLOG(@"key released: %@", event.characters);
}
-(BOOL) ccFlagsChanged:(NSEvent*)event
{
CCLOG(@"flags changed: %@", event.characters);
}
The flags changed event is received whenever the user presses or releases a modifier
key, regardless of whether any other key is pressed at the same time. You can use it to
implement controls that are assigned directly to a modifier key.
A very simplistic keyboard event check to react to presses or releases of the D key
would go something like this:
NSString* key = event.charactersIgnoringModifiers;
if ([key caseInsensitiveCompare:@"d"] == NSOrderedSame)
{
CCLOG(@"D key");
}
The problem with this approach is that depending on the user's locale, the keys may be
in different parts of the keyboard, possibly requiring the Option key as well. Further-
more, in many regions of the world, like Asia, Russia, or the Middle East, users may be
unable to (easily) create a D key on their keyboards.
Search Nedrilad ::




Custom Search