Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I map the mouse axes to my keyboard keys in the Mac OSX 10.6 Terminal? For example, moving the mouse up (positive x) triggers a keypress of W. Is this built in, or do I need a software package? The only search results I found were for mouse-driver, which I don't have on my system.

share|improve this question

migrated from Dec 28 '11 at 16:23

This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.

What exactly do you need to accomplish using mouse bindings like this? There is a Mouse Keys accessibility feature in OS X: System Preferences > Universal Access > Mouse (tab). – Jason Salaz Jan 27 '12 at 19:43

You could also use KeyRemap4MacBook.

You can assign other keys to the mouse key actions by creating a private.xml. The test folder has an XML file with all the predefined remappings.

share|improve this answer

There's Divvy, and SizeUp, and Flexiglass - they don't do exactly what you're after, but they do offer more flexible keyboard control over windowing. They're probably all worth a look.

Good luck!

share|improve this answer

As a workaround you could write a command line tool to move the mouse cursor around and then use your shell's programmable key-binding options to execute this command line tool when a specified key sequence is entered.



Compile with: 
gcc -Wall -Wextra -framework ApplicationServices -framework Foundation -o mvright mvright.m

Successfully compiled on:
Mac OS X 10.6.8

# in .bashrc; press ctrl-h keys to move mouse cursor to the right
bind -x '"\C-h": /usr/local/bin/mvright'  


- "Controlling the mouse from Python in OS X",, 
- "Move and click the mouse via code",


#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>

int main(void) {

   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

   // Get the current mouse location
   CGEventRef ourEvent = CGEventCreate(NULL);
   CGPoint ourLoc = CGEventGetLocation(ourEvent);

   //NSLog(@"Location? x= %f, y = %f", (float)ourLoc.x, (float)ourLoc.y);

   // The data structure CGPoint represents a point in a two-dimensional
   // coordinate system.  Here, X and Y distance from upper left, in pixels.
   CGPoint pt;
   pt.x = (float)ourLoc.x + 10.0;
   pt.y = (float)ourLoc.y;

   //NSLog(@"Location? x= %f, y = %f", (float)pt.x, (float)pt.y);

   CGEventRef eventRef;
   eventRef = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, pt, kCGMouseButtonCenter);

   //Apparently, a bug in xcode requires this next line
   //CGEventSetType(eventRef, kCGEventMouseMoved);

   CGEventPost(kCGSessionEventTap, eventRef);
   //CGEventPost(kCGHIDEventTap, eventRef);


   [pool release];
   return 0;

share|improve this answer
I read your code (which is very beauty full made ;) ), and realized that my question was wrong phrased (sorry :( ). I wanted to control the keys on the keyboard with the mouse axis. For example when x-axes is positive, key "d" will get pressed, x-axes is negative, key "a" will get pressed, y axes positive activates key "w" and y axes negative activates key "s" – elhombre Nov 17 '11 at 15:25

To receive mouse events in have a look at tools such as MouseTerm, USBOverdrive or ControllerMate!

If you feel like using a command line tool, have a look at altermouse.c as well (... possibly extended by using AppleScript).

For some X11 tools see xdotool and xautomation (the former being available via MacPorts).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.