I have been using emacs for a few months now and the position of control key had been really bugging me. I always had it in back of my mind that I will have to say good bye to emacs, eventually, because of its key bindings.
Then I came accross a hack that made space key work like ctrl in X. However I could not make it work. In any case, it could not be made to work with a terminal.
But I knew that if I could make the hack work, I will stick with emacs and I really wanted to. So I decided to make a change at kernel level. Below are the changes I made to my kernel. The space key acts like a space key if pressed and released without and other simultaneous key presses. Otherwise, it acts like a Ctrl key.
Since then I have not looked back and my wrists and my brain are now in a happy symbiotic relationship. :)
The code is just a hack and could be improved a lot, but it works for me and I have no complaints after over a month of use.
diff linux-2.6.38.5/drivers/input/input.c linux-2.6.38.5-MY/drivers/input/input.c
218a219,222
> // if(type==EV_KEY)
> // printk(KERN_ERR "Anshul: input_event %d %d %d",type, code, value);
>
>
346a351,353
> static int is_space_down = 0;
> static int space_act_like_ctrl = 0;
>
355a363,390
> if(code == 57 && value == 1){
> is_space_down = 1;
> printk(KERN_ERR "Converting space to ctrl");
> code = 29; //convert to control
> }
> else if( code == 57 && value == 0 && is_space_down){
> is_space_down = 0;
> if(space_act_like_ctrl){
> printk(KERN_ERR "Space acted like ctrl");
> space_act_like_ctrl = 0;
> code = 29; //convert to control
> }
> else{
> printk(KERN_ERR "space did not act like ctrl");
> input_handle_event(dev, type, 29, 0);
> input_handle_event(dev, type, 57, 1); //press space
> }
> }
> else if(is_space_down && value == 1){
> space_act_like_ctrl = 1;
> printk(KERN_ERR "another key was pressed with space");
> }
> else if(is_space_down && code == 29 && value == 0){
> //return; //ignore if control is released while space is pressed
> printk(KERN_ERR "ctrl release ignored while space was pressed");
> spin_unlock_irqrestore(&dev->event_lock, flags);
> return;
> }
361c396
<
---
>
Ignore the printk's, they were there just for debugging.
ReplyDelete