• 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: Keyboard short-cuts edit field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keyboard short-cuts edit field


  • Subject: Re: Keyboard short-cuts edit field
  • From: j o a r <email@hidden>
  • Date: Wed, 3 May 2006 21:30:35 +0200


On 3 maj 2006, at 19.08, Eric Long wrote:

I don't know how to intercept the key events for an NSTextField, which seems
like the best way to do things here, so I opted to watch for
textDidBeginEditing and textDidEndEditing calls. In textDidBeginEditing, I
set a timer to repeatedly call GetKeys() and set the string value of the
edit field accordingly. In textDidEndEditing I invalidate the timer.
<snip>
Is there a better way to do this? If so, can you explain it to me?

If I'm on the right track, how can I alleviate the problem of the beeps and
such?

Personally, I would never use timers like that. You get events for every new character, so why use a timer? Use delayed actions only when you absolutely have to.


I implemented a control to grab user keyboard shortcut once. The capture of the key events was in my case done by a subclass to NSBrowser (as the browser was used to represent the tree of available menu items), and done something like this:

- (BOOL) performKeyEquivalent:(NSEvent *) event
{
NSString *keyEquiv = [event charactersIgnoringModifiers];
unsigned int eventFlags = ([self modifierFlags] & NSDeviceIndependentModifierFlagsMask);

/*
NSLog(@"keyEvent: %@", aKeyEquiv);
NSLog(@"characters: %@", [event characters]);
NSLog(@"charactersIgnoringModifiers: %@", keyEquiv);
NSLog(@"deviceIndependentModifierFlags: %d", eventFlags);
NSLog(@"NSControlKeyMask: %d, %d", ((eventFlags & NSControlKeyMask) != 0), NSControlKeyMask);
NSLog(@"NSAlternateKeyMask: %d, %d", ((eventFlags & NSAlternateKeyMask) != 0), NSAlternateKeyMask);
NSLog(@"NSShiftKeyMask: %d, %d", ((eventFlags & NSShiftKeyMask) != 0), NSShiftKeyMask);
NSLog(@"NSAlphaShiftKeyMask: %d, %d", ((eventFlags & NSAlphaShiftKeyMask) != 0), NSAlphaShiftKeyMask);
NSLog(@"NSCommandKeyMask: %d, %d", ((eventFlags & NSCommandKeyMask) != 0), NSCommandKeyMask);
*/
}


I use a class to represent a keyboard equivalent:

MyKeyEquivalent *keyEquiv = [MyKeyEquivalent keyEquivalentWithString: keyEquiv modifierMask: eventFlags];

This class is used to store & restore the set of key equivalents that the user has specified.
It also has a method to return a string representation when you need to display it:


	- (NSString *) stringRepresentation;

Special characters are created using their unicode values. For example, to represent the CMD key I create a string like this:

	unichar tm[1] = {0x2318};
	NSString *cmdKeyStr = [NSString stringWithCharacters: tm length: 1];


j o a r


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

References: 
 >Keyboard short-cuts edit field (From: Eric Long <email@hidden>)

  • Prev by Date: Re: Keyboard short-cuts edit field
  • Next by Date: Sound Manager?
  • Previous by thread: Re: Keyboard short-cuts edit field
  • Next by thread: Re: Keyboard short-cuts edit field
  • Index(es):
    • Date
    • Thread