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.
4 Answers
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.
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.
http://www.irradiatedsoftware.com/sizeup/
http://www.nulana.com/flexiglass
Good luck!
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.
/*
File:
mvright.m
Compile with:
gcc -Wall -Wextra -framework ApplicationServices -framework Foundation -o mvright mvright.m
Successfully compiled on:
Mac OS X 10.6.8
Usage:
./mvright
# in .bashrc; press ctrl-h keys to move mouse cursor to the right
bind -x '"\C-h": /usr/local/bin/mvright'
References:
- "Controlling the mouse from Python in OS X",
http://stackoverflow.com/questions/281133/controlling-the-mouse-from-python-in-os-x,
http://synergy-foss.org
- "Move and click the mouse via code",
http://hints.macworld.com/article.php?story=2008051406323031
*/
#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);
CFRelease(eventRef);
CFRelease(ourEvent);
[pool release];
return 0;
}
-
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"– elhombreNov 17, 2011 at 15:25
To receive mouse events in Terminal.app 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).
System Preferences > Universal Access > Mouse (tab)
.