• 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: Simulating Text Input
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simulating Text Input


  • Subject: Re: Simulating Text Input
  • From: Eiko Bleicher <email@hidden>
  • Date: Thu, 20 May 2010 17:04:28 +0200

Flavio,

thanks! This should be a good starting point for the lookup table, it does what I wanted to do (at least it looks like it). :-)

Eiko

Am 20.05.2010 um 16:57 schrieb Flavio Donadio:

> Eiko,
>
>
> There's some code in OSXvnc that might help with this. Check this file:
>
> http://osxvnc.cvs.sourceforge.net/viewvc/osxvnc/OSXvnc/VNCBundle.m?revision=1.2&view=markup
>
> It creates a "keyTable" with Unicode characters as indexes and CGKeyCodes as values, based on the selected keyboard layout.  Pseudo-code:
>
> CGEventCreateKeyboardEvent (NULL, (CGKeyCode)theKeyTable[someUnichar], true);
>
>
> Cheers,
> Flavio
>
>
> On 20/05/2010, at 11:13, Eiko Bleicher wrote:
>
>> Sure, CGEventCreateKeyboardEvent was the first obvious way (and probably the one I'll stick with).
>>
>> Just be warned that the codes are different for each keyboard layout, so already the stock code
>>
>> CGEventRef event1, event2, event3, event4;
>> event1 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, true);
>> event2 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, true);
>> event3 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, false);
>> event4 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, false);
>>
>> will produce varying results - "Z" on English QUERTY keyboards, "Y" on German QUERTZ ones. Given many many different layouts it is at least not trivial to get the characters / strings you need...
>>
>> Eiko
>>
>>
>> Am 20.05.2010 um 15:55 schrieb Flavio Donadio:
>>
>>> Paul and Eiko,
>>>
>>>
>>> I just checked OSXvnc's source code. Their code led me to the right place, but it's fairly complex for a beginner (like myself) to learn how to post keyboard events (generate keystrokes or simulating keyboard input).
>>>
>>> The functions needed for this are in Quartz / Core Graphics. OSXvnc still uses CGPostKeyboardEvent, which is now deprecated in 10.6. Apple suggests CGEventCreateKeyboardEvent as a substitute.
>>>
>>> Check Developer Documentation for more information. There's a code snippet in CGEventCreateKeyboardEvent's reference that makes things very clear.
>>>
>>>
>>> Cheers,
>>> Flavio
>>>
>>> On 19/05/2010, at 16:53, Paul Sanders wrote:
>>>
>>>>> I am interested in simulating text input (maybe via generating keystrokes), but never found an example for that.
>>>>
>>>> Well VNC must simulate keystrokes somewhere along the line, although finding it may take a bit of digging around in the sources.  As you say, mapping all the various keycodes is likely to be painful.
>>>>
>>>> Paul Sanders.
>>>>
>>>
>>
>

_______________________________________________

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

References: 
 >Re: Simulating Text Input (From: Flavio Donadio <email@hidden>)
 >Re: Simulating Text Input (From: "Paul Sanders" <email@hidden>)
 >Re: Simulating Text Input (From: Flavio Donadio <email@hidden>)
 >Re: Simulating Text Input (From: Eiko Bleicher <email@hidden>)
 >Re: Simulating Text Input (From: Flavio Donadio <email@hidden>)

  • Prev by Date: Re: Regarding MVC design pattern
  • Next by Date: Re: Regarding MVC design pattern
  • Previous by thread: Re: Simulating Text Input
  • Next by thread: Problem resizing an attachment in a NSTextView
  • Index(es):
    • Date
    • Thread