Reputation: 5790
Recently I wanted to make a small utility that would allow me to arbitrarily remap the keys on my keyboard to correspond to different character inputs.
How is this normally accomplished from a system programming perspective and what should I reference in order to learn how to do this?
Thanks!
Upvotes: 0
Views: 350
Reputation: 863
I may be mistaken, but I believe it depends entirely on what your running (what your window manager is). For example, if you were running something with openbox (e.g. lubuntu), then you could reference the following:
http://openbox.org/wiki/Help:Bindings
There are similar concepts for Gnome. If you are looking to change Gnome, you may want to go peak around how gnome-tweak-tool changes things (specifically look at the keybindings -- tweak does a lot more!).
In both instances, I suggest using Python (gnome-tweak-tool would be a great reference point for how to do this) because it is very convenient to write GUIs and will allow you to change the necessary files easily :)
If you are using Ubuntu, this post may be useful for you:
https://askubuntu.com/questions/115333/how-do-i-disable-the-sleep-button-on-my-keyboard
Their question was for one specific key, but the top two answers are relevant. The answer with dconf-tools may help you get a better understanding of where things are located.
So in the end, you will end up needing to configure some files differently, but where those files are and how you change them depends on your window manager.
The above is useful for say disabling CAPS_LOCK or swapping L_SHIFT and L_CTRL or something. If you are asking about generically changing any keyboard input, then there's a lot more going on behind the scenes. You may want to read this article for a good explanation of what is going on:
http://www.linuxjournal.com/article/1080
So if you want to remap things, say switching the 'a' and 'f' keys, you would need to capture the keyevent for 'a', and send the 'f' key event instead. There are many ways to see what keys are being pressed, this may be a good place to start:
https://superuser.com/questions/248517/show-keys-pressed-in-linux
Changing things at this level is much more difficult / dangerous, so make sure you are careful!
Hope that helps a little! If this isn't what you were trying to do, please include more information in your question about what the actual goals of your program are.
Upvotes: 1