• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to handle non-character keyboard events?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to handle non-character keyboard events?


  • Subject: Re: How to handle non-character keyboard events?
  • From: Stéphane Sudre <email@hidden>
  • Date: Fri, 7 Dec 2001 17:11:07 +0100

On Friday, December 7, 2001, at 04:51 PM, Andri Benassi wrote:

I am trying to get my small program to recognize arrow key inputs from
the keyboard. I have the following method (kiped from Mike Beam's
wonderful article on O'Reilly):

- (void)keyDown:(NSEvent *)theEvent {
NSString *keyChar = [theEvent characters];

if ( [keyChar isEqualToString:@"c"] ) {
[path removeAllPoints];
[self setNeedsDisplay:YES];
}
}

- (BOOL)acceptsFirstResponder {
return YES;
}

- (void) keyDown:(NSEvent *) theEvent
{
NSString * tString;
unsigned int stringLength;
unsigned int i;
unichar tChar;

tString= [theEvent characters];

stringLength=[tString length];

for(i=0;i<stringLength;i++)
{
tChar=[tString characterAtIndex:i];

switch(tChar)
{
case NSUpArrowFunctionKey:
rotX_-=KEY_ROTATION;
if (rotX_<0) rotX_+=360;
if (rotX_>360) rotX_-=360;

[self render];
break;
case NSDownArrowFunctionKey:
rotX_+=KEY_ROTATION;
if (rotX_<0) rotX_+=360;
if (rotX_>360) rotX_-=360;

[self render];
break;
case NSLeftArrowFunctionKey:
if (timer_!=NULL)
{
[timer_ invalidate];
[timer_ release];
timer_=NULL;
}
rotY_-=KEY_ROTATION;
if (rotY_<0) rotY_+=360;
if (rotY_>360) rotY_-=360;

[self render];
break;
case NSRightArrowFunctionKey:
if (timer_!=NULL)
{
[timer_ invalidate];
[timer_ release];
timer_=NULL;
}
rotY_+=KEY_ROTATION;
if (rotY_<0) rotY_+=360;
if (rotY_>360) rotY_-=360;

[self render];
break;
case NSF1FunctionKey:
wireFrame_=!wireFrame_;

if (wireFrame_==YES) SetRenderingMode(SM_WIREFRAME);
else SetRenderingMode(SM_FILLED);
[self render];
break;
case NSF2FunctionKey:
showAxis_=!showAxis_;
[self render];
break;
case NSF3FunctionKey:
showFog_=!showFog_;
[self render];
break;
case NSF4FunctionKey:
SetColoringMode(SM_LAYER_COLOR-GetColoringMode());
[self render];
break;

}
}
}


References: 
 >How to handle non-character keyboard events? (From: André Benassi <email@hidden>)

  • Prev by Date: Re: How to handle non-character keyboard events?
  • Next by Date: Re: is [uiObject display] necessary?
  • Previous by thread: Re: How to handle non-character keyboard events?
  • Next by thread: monitoring file modifications
  • Index(es):
    • Date
    • Thread