Re: Inserting text
Re: Inserting text
- Subject: Re: Inserting text
- From: Guy English <email@hidden>
- Date: Mon, 17 Jan 2005 13:53:11 -0500
Oooh - that was smart. :) I would have tried sticking the whole
string in the buffer. Nice work!
I'm not in front of my Mac but I believe it's possible for the user to
re-map command-v though. You'd be able to work out what key to stick
into the buffer from the plist that gets kicked out by the keyboard
shortcut config panel. Again, just so it works in all environments -
your solution is great.
Guy
On Mon, 17 Jan 2005 12:01:29 -0500, Austin Sarner <email@hidden> wrote:
> Here is my *working* solution. Thanks a bunch for the input.
>
> First I set the clipboard contents to the string I want to insert. I
> then simulate the command-v press using:
>
> CGInhibitLocalEvents(YES);
> CGInhibitLocalEvents(YES);
> CGEnableEventStateCombining(NO);
>
> CGPostKeyboardEvent((CGCharCode)NULL, (CGKeyCode)55, true);
> CGPostKeyboardEvent((CGCharCode)'v', (CGKeyCode)9, true);
> CGPostKeyboardEvent((CGCharCode)'v', (CGKeyCode)9, false);
> CGPostKeyboardEvent((CGCharCode)NULL, (CGKeyCode)55, false);
>
> CGSetLocalEventsFilterDuringSupressionState(kCGEventFilterMaskPermitAllE
> vents, kCGEventSupressionStateSupressionInterval);
>
> CGEnableEventStateCombining(YES);
> CGInhibitLocalEvents(NO);
>
> Then I restore the clipboard contents... works like a charm 8).
>
> Thanks again for your responses.
>
> On Jan 17, 2005, at 11:10 AM, Guy English wrote:
>
> > You could, not that I think any of these are great ideas, but you
> > could:
> >
> > a) write an InputManager and send it notifications that it'll post
> > into an app. An InputManager runs in the process space of each
> > application. It's also Cocoa only.
> >
> > b) Use the Accessibility stuff. You can get all kinds of info about
> > controls and interact with them too. The user will need to turn
> > support on specifically though.
> >
> > c) AppleScript / AppleEvents - for cocoa apps it'll be a little easier
> > since they have the default text suite usually (if they support
> > applescript at all). But in general you'll need to write support for
> > specific common apps and maybe fall back to guessing what to do after
> > programmatically examining an apps script dictionary. Which would be
> > hard.
> >
> > d) Use CoreGraphics Remote operation to post lowlevel events into the
> > input stream. You can jam your string into the input buffer and it'll
> > go through the standard even dispatch mechanisms. It's problematic
> > because there isn't a fool proof way to turn a given string into a set
> > of keyboard inputs but it's probably the most general, least invasive
> > method and easiest method to implement.
> >
> > Good luck,
> > Guy
> >
> >
> > On Sun, 16 Jan 2005 18:12:25 -0500, Austin Sarner
> > <email@hidden> wrote:
> >> Is there any way to insert a string into the frontmost application?
> >> For instance if you have a status item based app with text edit open
> >> and you select an item from the status item menu - it would add the
> >> selected item to textedit. I know this is possible via system
> >> services, but is it possible to do something similar with a standard
> >> cocoa app? Thanks a bunch.
> >>
> >> _______________________________________________
> >> Do not post admin requests to the list. They will be ignored.
> >> Cocoa-dev mailing list (email@hidden)
> >> Help/Unsubscribe/Update your Subscription:
> >> email@hidden
> >>
> >> This email sent to email@hidden
> >>
> > _______________________________________________
> > 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
>
>
_______________________________________________
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