I would like to have some way to specify that when I am focused on Spotify.app and I press the j key that it will translate into a ↓ key and be sent to the app. I would like this because I like vim style navigation but Spotify does not support remapping keyboard shortcuts.
5 Answers
@iGameRam's suggestion of KeyRemap4MacBook ended up working for me. I selected KeyRemap4MacBook because I am already using it to remap keys for me system wide. To do this I had to read the reference manual.
From the reference manual I found that there is a private.xml
file that enables me to add more remapping values to KeyRemap4MacBook. By going to the KeyRemap4MacBook pref pane, going to the "Misc & Uninstall" tab and selecting "Open private.xml" I was able to open the file.
I had to add two elements to my private.xml
. The first was:
<appdef>
<appname>SPOTIFY</appname>
<equal>com.spotify.client</equal>
</appdef>
This is because KeyRemap4MacBook does not ship with an app definition for Spotify. It does ship with many others. I need the app definition so my keyboard keybindings only apply for Spotify and are not system wide.
The second element I added was:
<item>
<name>Spotify Vim Style Nav</name>
<appendix>J and K works in Spotify</appendix>
<identifier>private.spotify.vim_style_nav</identifier>
<only>SPOTIFY</only>
<autogen>--KeyToKey-- KeyCode::J, KeyCode::CURSOR_DOWN</autogen>
<autogen>--KeyToKey-- KeyCode::K, KeyCode::CURSOR_UP</autogen>
</item>
This is the actual definition of the key bindings. The <identifier>
tag is supposed to be unique for every key mapping. The manual suggests prefixing the identifier with private.
. The <only>
tag has to match an appname defined in the private.xml
or shipped with KeyRemap4MacBook.
The <autogen>
tags are supposed to contain the mappings. The manual has many examples on what kind of mappings that can be created. The two I have map the J and K keys to the Down and Up keys respectively.
Once the file has been saved, I just needed to press the "ReloadXML" button and then my mapping appeared as an option in the menu.
After selecting it everything worked as I wanted.
There are a couple of third party apps that can do what you are asking for (as i understood it ) , KeyRemap , Double Command . Please try this and let us know if this is what you were looking for.
-
I already have KeyRemap but I don't see any option that lets me map keys in an app specific manner. Could you post more information on how to do that? Commented Jul 10, 2012 at 16:07
-
@ZameerManji pqrs.org/macosx/keyremap4macbook/xml-appdef.html.en– LriCommented Jul 10, 2012 at 19:07
-
@LauriRanta Thanks for the link. I will try to come up with a solution and post back here if it works out. Commented Jul 10, 2012 at 21:11
-
@iGameRam: See my answer for what I did and how it worked out for me. Commented Jul 11, 2012 at 6:26
-
Thats great. Hope i could point you to right direction :-)– iGameRamCommented Jul 11, 2012 at 11:41
If the action you want to perform can also be accessed through the menubar you could add a keyboard shortcut in system preferences/keyboard/keyboard shortcuts/Application short cuts.
-
The keyboard preference only works with modifiers, not bare keys, no?– bmike ♦Commented Jul 10, 2012 at 11:24
-
1You are right, only shortcuts with modifiers can be added like this.– LauraCommented Jul 10, 2012 at 14:22
-
You can use other key combinations by editing the property lists in ~/Library/Preferences/ directly or with defaults.– LriCommented Jul 10, 2012 at 19:11
-
Now you got me curious, which plist and with properties have to be changed to do that?– LauraCommented Jul 12, 2012 at 13:50
Try Keyboard Maestro. It does a lot more than just remap keys, but it can be very useful for that purpose. You can set up all sorts of macros and actions on a global or per-app basis.
I know it works for controllers to keyboard, not sure about keyboard to keyboard, but you can try ControllerMate.
ControllerMate is a system that generates keyboard, mouse, and MIDI activity in response to triggers from gamepads, keypads, MIDI controllers, and other general-purpose input devices. It allows many types of devices to be used with software that would normally be compatible only with a keyboard, mouse, or MIDI source.
ControllerMate's internal devices generate activity based on a system of building blocks. Some building blocks respond to controls on input devices, other blocks trigger activity on ControllerMate's internal mouse and keyboard. Building blocks that implement timers, apply simple or complex logic, or perform basic math can also be created. Each individual building block performs a basic task, combinations of blocks can perform complex and creative functions.
A good thing about that app is you can choose to activate the remap for only the apps you want.