I want my program to press certain keys on my keyboard without me doing it physically. for example, button in my app for (command + UP) if user press the button, my app will do same thing in the keyboard . How i do this?
Asked
Active
Viewed 554 times
0
-
2[Simulate keypress on OS X](http://stackoverflow.com/questions/1938509/how-to-simulate-a-low-level-keypress-on-os-x), unless you mean you want the computer to physically move the actual keys, which I think will involve installing some servos. :) – jscs Apr 09 '11 at 05:27
-
Josh: Your comment should be an answer; it is the solution to the stated problem. – titaniumdecoy Apr 09 '11 at 05:52
-
@titaniumdecoy: Well, I was trying to point out in a friendly way that this is essentially a duplicate. Reading the comments now, however, I'm not completely sure what the OP is asking for. – jscs Apr 09 '11 at 18:16
2 Answers
2
I'm assuming that you have a function that will be triggered when the user presses the command + up keys. So to illustrate:
command + up ---> call function
And you are asking is there a way to:
click a button ---> somehow trigger command + up event ---> call function
But why not you just do:
click a button ---> call function
Much simpler and more straight-forward. Is there any specific reason you still need the command + up event triggered?

Lukman
- 18,462
- 6
- 56
- 66
-
yes that what I want :: click a button that's in my app ----> call function that related to command + UP without using keyboard – DAVEd Apr 09 '11 at 07:37
-
DAVE: Right, so why don't you just separate out the logic into a function and call it when the keys are pressed and also when the button is clicked? You don't need to simulate a keypress. – Ed S. Apr 09 '11 at 18:50
0
I am assuming it is that you have linked a menu item to an IBAction IN Interface Builder and given it a short cut of command+ up. If so just link your button to the same action
edit* Have a look at these.
Xcode 4 xcode_help-interface_builder help including video examples
xcode 3 - Interface Builder User Guide pdf look at chapter 7. ( I could not find the guide on apples site, it all points to v4?)

markhunte
- 6,805
- 2
- 25
- 44
-
So in IB. Select your object (controller) that has the Action (function). And then select the Connections inspector. Look for the correct Received Action. And click it's small circle at the end of it and drag the connection line to your button. – markhunte Apr 09 '11 at 08:42