• 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
Send Key Event to Focused Window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Send Key Event to Focused Window


  • Subject: Send Key Event to Focused Window
  • From: Daniel <email@hidden>
  • Date: Wed, 18 Jun 2008 09:31:17 +0200

Hi to all,

I'm developing a tool for assistive input and my question is how can I
send a key event (like a keyboard press event) to the current window
(whatever this one could be), for data input.

I've tried the following, but only a beep is produced by my machine.

<snippet>
    id keyTarget = [[NSApp keyWindow] firstResponder];
    NSEvent *aKeyDownEvent = [NSEvent keyEventWithType:NSKeyDown
		location:NSMakePoint(0,0)
		modifierFlags:0
		timestamp:[NSDate timeIntervalSinceReferenceDate]
		windowNumber:[[NSApp keyWindow] windowNumber]
		context:[[NSApp keyWindow] graphicsContext]
		characters:@"Q"
		charactersIgnoringModifiers:@"Q"
		isARepeat:NO keyCode:0];
    [keyTarget keyDown:aKeyDownEvent];
</snippet>

Thank you in advance,
Daniel
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Send Key Event to Focused Window
      • From: j o a r <email@hidden>
  • Prev by Date: Re: Getting all subclasses
  • Next by Date: Re: Send Key Event to Focused Window
  • Previous by thread: Re: does NSTextField always use UTF8 encoding
  • Next by thread: Re: Send Key Event to Focused Window
  • Index(es):
    • Date
    • Thread