• 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: What NSEvent contains text from Ink input? [Solution]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What NSEvent contains text from Ink input? [Solution]


  • Subject: Re: What NSEvent contains text from Ink input? [Solution]
  • From: Ricky Sharp <email@hidden>
  • Date: Sun, 20 Nov 2005 18:34:27 -0600

Someone was kind enough to recommend using Carbon events which does indeed work.

Here's the solution in case anyone else needs Ink input outside of NSTextField/NSTextArea:

@interface MyAppController (Private)
- (void)ink:(NSString*)aString;
pascal OSStatus ApplicationInkEventHandler (EventHandlerCallRef inHandler, EventRef inEvent, void* ioUserData);
@end


@implementation IIAppController

- (void)ink:(NSString*)aString
{
    NSLog(@"ink_II \"%@\"", aString);
}

pascal OSStatus ApplicationInkEventHandler (EventHandlerCallRef inHandler, EventRef inEvent, void* ioUserData)
{
OSStatus theResult = eventNotHandledErr;


if ((GetEventClass (inEvent) == kEventClassInk) && (GetEventKind (inEvent) == kEventInkText))
{
InkTextRef theInkText = NULL;

theResult = GetEventParameter (inEvent, kEventParamInkTextRef,
typePtr, NULL, sizeof (InkTextRef), NULL, &theInkText);

if ((theResult == noErr) && (theInkText != NULL))
{
CFStringRef theInkString = InkTextCreateCFString (theInkText, 0);

if (theInkString != NULL)
{
[(IIAppController*) ioUserData ink:(NSString*) theInkString];

CFRelease (theInkString);
}
}
}

return theResult;
}


- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
InkSetApplicationWritingMode (kInkWriteAnywhereInApp);
InkSetApplicationRecognitionMode (kInkRecognitionGesture | kInkRecognitionText);

EventTypeSpec applicationEventList[] = { { kEventClassInk, kEventInkText } };

OSStatus theOSStatus = InstallApplicationEventHandler (NewEventHandlerUPP (ApplicationInkEventHandler),
1, applicationEventList, self, NULL);
}


Note that gestures that simulate keys (e.g. delete, enter) will still come in via keyboard events (and thus your keyDown: will be called). One could modify the above to also listen for kEventInkGesture. However, I haven't done any testing with that, so I don't know if you'd still get the keydown if you return noErr from ApplicationInkEventHandler after handling the gesture event. My take is that an NSEvent should not be created in that situation.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
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


  • Follow-Ups:
    • Re: What NSEvent contains text from Ink input? [Solution]
      • From: Ricky Sharp <email@hidden>
References: 
 >What NSEvent contains text from Ink input? (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Problems making a framework (was tabbed class like Safari)
  • Next by Date: Re: NSPredicate performance considerations
  • Previous by thread: What NSEvent contains text from Ink input?
  • Next by thread: Re: What NSEvent contains text from Ink input? [Solution]
  • Index(es):
    • Date
    • Thread