Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

satyam90

macrumors regular
Original poster
Jul 30, 2007
242
0
Bangalore, India
Hi,

I would like to know the way to post events from code. I mean events like mouse click, keyboard click, menu click etc.....
Is it possible?

Regards,
Satya.
 

toddburch

macrumors 6502a
Dec 4, 2006
748
0
Katy, Texas
Kind of a vague question. Post to who or what? Do you mean capture?

There certainly is a framework in place to grab all these events. (Carbon & Cocoa, perhaps others) via their event model.

Todd
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
If you intend on generating input events (key presses, mouse clicks, etc) at a low level (so that normal apps will respond to them as if the user had caused them to happen), you could look in to "event taps."

This API was introduced in 10.4. There were a lot of bugs in this API 10.4.0.
It was a lot better in 10.4.10 (that's the last time I used it), though there were still some significant bugs.

I used it to create a daemon that converts enter key presses and releases to right-mouse button presses and releases.

I remember that one of the bugs I ran in to was that when I created a new event, the input system of the mac hung (until reboot). I thought I had followed the documentation and tried a few things to resolve it but without success (For my purposes, I realized that I didn't have to create a new event, just repurpose the existing one, so ultimately I just worked around the problem). It seems like you are mostly concerned with creating new events, though, so be prepared. Maybe I was doing something wrong and you will figure it out where I didn't, or maybe it was a bug and Apple fixed it.

The other route to go is to create a virtual keyboard driver and have it generate events. This is even lower level than the event taps and would work if event taps aren't up to the task. In that case, you'll want to go though the docs or the IOKit. This will be a bunch more work than the event taps, though. If you go this way, you might want to look for an opensource project that implements something like this to give you a leg up.
 

satyam90

macrumors regular
Original poster
Jul 30, 2007
242
0
Bangalore, India
Let me explain what I am expecting clearly.
For example to generate a Menu event: My application has Menu Item File->Open, now for accessing it we have to move the mouse to "File" click it and then click on "Open". On clicking "Open" something will happen.
I want to achieve this using code instead of moving mouse and clicking on menu items.
Like this event how to implement mouse events, keyboard events etc.

I think it is clear this time.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Let me explain what I am expecting clearly.
For example to generate a Menu event: My application has Menu Item File->Open, now for accessing it we have to move the mouse to "File" click it and then click on "Open". On clicking "Open" something will happen.
I want to achieve this using code instead of moving mouse and clicking on menu items.
Like this event how to implement mouse events, keyboard events etc.

I think it is clear this time.

Can you try this even more clearly? What is "My application"? Is it an application that you are developing, or an application that you purchased without any access to the source code? Do you want to write code to do this, or would you be happy with a third party application that can do this?
 

markm

macrumors newbie
Sep 23, 2003
12
0
Canada
You do not need to imitate an event. If you are trying to call one of the default menu items, you just set the delegate and message it directly in code. If you are trying to imitate selecting a menu item that you created, you can just message the target with the action that you hooked up in IB.

Mark
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.