Author Topic: emulating the HHKB on a standard keyboard (linux)  (Read 9554 times)

0 Members and 1 Guest are viewing this topic.

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« on: Mon, 04 May 2009, 18:46:41 »
Don't know about doing this in windows or mac but would like to do it in linux. Running ubuntu 9.04 and gnome if it matters.

As an example I want to map the Win key + L key to be Page Up.

I am able to swap escape with tilde using xmodmap, but can't figure out how to combine multiple keys.

It would be nice to emulate the HHKB layout on a regular keyboard.

Anyone here know how to do this. Google and Clusty are  not being helpful.
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline IBI

  • Posts: 492
emulating the HHKB on a standard keyboard (linux)
« Reply #1 on: Mon, 04 May 2009, 20:42:37 »
Why not just use a macro program? Autohotkey is popular for windows but I'm sure there's some Linux equivelent.
Owned: Raptor-Gaming K1 (linear MX)(Broken), IBM Model M UK, Dell AT102W, Left-handed keyboard with Type 1 Simplified Alps.

Offline xyzzy

  • Posts: 155
  • Location: EU
emulating the HHKB on a standard keyboard (linux)
« Reply #2 on: Tue, 05 May 2009, 02:22:39 »
Have you tried xbindkeys?

I think it lets map keyboard shortcuts to actions, I'm not sure if it also allows you to map keys combinations to other keys...

IBM Model F62 (Ellipse's) • PFU HHKB Pro Type S Hybrid • PFU HHKB Pro • Leopold FC660C • IBM Model M SSK 1391472 • IBM Model M SSK UNI04C6 • IBM Model M 1391405 (x4) • Cherry MX 1800 Compact (blue Cherry) • Cherry MX 11900 Touchboard (brown Cherry) • Dell AT102W (black Alps) • Apple Extended Keyboard II (cream Alps) • Acer 6312-TA (black Acer) • Unikey KWD-601 (white Cherry)

Offline cb951303

  • Posts: 72
emulating the HHKB on a standard keyboard (linux)
« Reply #3 on: Tue, 05 May 2009, 09:19:19 »
I'm not sure if it helps but there is a good amount of layout options at  Preferences > Keyboard > Layouts > Layout Options
Filco Zero FKBN87Z/EB
Kensington Orbit K72337US

Offline o2dazone

  • Posts: 953
emulating the HHKB on a standard keyboard (linux)
« Reply #4 on: Tue, 05 May 2009, 10:00:59 »
if I want to permanently switch one key with another (ie. Left Control <--> Caps Lock) I use Keytweak...because it actually sends the real scancode for that key.

For combination type stuff, I use Autohotkey (it's really easy to use too), and instead of sending a scancode, it just intercepts the stroke and puts something else there instead. It's also really nice for automating things you don't want to deal with (like going afk in battlegrounds lol)

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #5 on: Tue, 05 May 2009, 14:59:44 »
I use xmodmap now to swap keys, for example:

#! /bin/sh

#swap escape with tilde on the model m spacesaver

#Using the original tilde key as escape
xmodmap -e "keycode 49 = Escape"



#Using the original escape key as tilde and tick
xmodmap -e "keycode 9 = asciitilde grave"



I haven't figured out how to map multiple keys yet, for example:

The windows k is mapped as Meta_L

xev returns this:

KeyRelease event, serial 35, synthetic NO, window 0x5a00001,
    root 0x1a7, subw 0x0, time 157126402, (102,774), root:(1646,828),
    state 0x40, keycode 133 (keysym 0xffe7, Meta_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False


The k key returns this:


KeyPress event, serial 35, synthetic NO, window 0x5a00001,
    root 0x1a7, subw 0x0, time 157178744, (-282,751), root:(1262,805),
    state 0x0, keycode 45 (keysym 0x6b, k), same_screen YES,
    XLookupString gives 1 bytes: (6b) "k"
    XmbLookupString gives 1 bytes: (6b) "k"
    XFilterEvent returns: False

 
 
The home key returns:

KeyPress event, serial 35, synthetic NO, window 0x5a00001,
    root 0x1a7, subw 0x0, time 157241473, (-184,650), root:(1360,704),
    state 0x0, keycode 110 (keysym 0xff50, Home), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False
 
I want Meta_L + k to equal Home

I just haven't figured how to write it yet.
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline cmr

  • Posts: 295
emulating the HHKB on a standard keyboard (linux)
« Reply #6 on: Tue, 05 May 2009, 22:56:44 »
xmodmap is what you'll want for this

when you're done writing about 100k of .xmodmap can you let me know how i can turn pause into a spare Win_L

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #7 on: Wed, 06 May 2009, 04:47:59 »
Thats easy to do.




The left Windows key returns this:

KeyPress event, serial 35, synthetic NO, window 0x4e00001,
    root 0x1a7, subw 0x4e00002, time 206698266, (22,55), root:(1366,109),
    state 0x0, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False





The Pause key returns this:

KeyPress event, serial 35, synthetic NO, window 0x5000001,
    root 0x1a7, subw 0x0, time 206763836, (1108,-233), root:(1111,663),
    state 0x0, keycode 127 (keysym 0xff13, Pause), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False






To turn pause into a spare Win_L key do this:

xmodmap -e "keycode 127 = Super_L"
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline pmyshkin

  • Posts: 71
emulating the HHKB on a standard keyboard (linux)
« Reply #8 on: Sun, 10 May 2009, 13:56:09 »
You can do this with the xserver keymaps. I'm not really familiar with this, but you can look in /usr/share/kbd/keymaps/i386/ (might be different in your distro) for some examples, notably emacs.map.gz.

Offline iMav

  • geekhack creator/founder
  • Location: Valley City, ND
  • "Τα εργαλεία σας είναι σημαντικά."
emulating the HHKB on a standard keyboard (linux)
« Reply #9 on: Sun, 10 May 2009, 16:52:35 »
Mapping caps lock to Cntrl and swapping the "\|" and backspace keys has typically been good enough for me to stay consistent between HHKB and other keyboards.

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #10 on: Sun, 10 May 2009, 19:34:10 »
Quote from: iMav;90190
Mapping caps lock to Cntrl and swapping the "\|" and backspace keys has typically been good enough for me to stay consistent between HHKB and other keyboards.


swapping the caps lock and control keys is trivial in gnome. But I am having issues with the \| and backspace.

I can swap the backspace key with no issues, but can only get either | or \ to work at any given time.  iMav, you are running mac os, right? I assume their is a simple way for you to make the swap.
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #11 on: Sun, 07 June 2009, 08:33:23 »
Got a reply from the ubuntu forum on how to swap the backspace and pipe keys.

The key is to edit the file,

/usr/share/X11/xkb/symbols/pc

and change the following:

key {
type="CTRL+ALT",
symbols[Group1]= [ BackSpace, Terminate_Server ]
};

to:

key {
type="TWO_LEVEL",
symbols[Group1]= [ BackSpace, Terminate_Server ]
};



I put this in a bash file that I can call on startup or from the command line

#swap the backspace and pipe key, like it is on a HHKB
xmodmap -e "keycode 51 = BackSpace"
xmodmap -e "keycode 22 = backslash bar"


Now all I need to figure is the Fnc + keys for Page Up/Down, Home/End etc.
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #12 on: Sun, 07 June 2009, 11:43:12 »
thanks ripster. I am not putting a whole lot of time into this as it IS a pain in the butt. But I have feelers out in multiple forums. From what I am seeing, no one has tried to emulate an HHKB in linux yet.

Swapping keys is fairly trivial, especially lettered keys. But keys like Backspace, Tab and so on seem to be treated differently.

One of the things I notice when running xmodmap -pke is this:

keycode  52 = z Z z Z z Z

Notice the code is 52 and its for the letter z.

What makes it interesting is that there are 6 instances of the letter z

The first one is simply when you press the 'z' key. Its lower case...

The second instance is 'Z' which you get when you hit Shift + z.

It is the next 4 instances that I can't figure out.

I have tried the obvious, Alt, Cntrl, Super, Meta but can't get it to register.

What I am afraid of is that there is another /usr/share/X11/xkb/symbols/pc
file that has to be edited, or something else entirely.

Once I have it worked out, I will clean up this thread and finalize it.

This is one of the things that makes linux a pain to use. Granted, there are not that many people out there trying to do this. And to be blunt, the ones that do have the brain power  to knock it out in a few minutes.
I am somewhere in between, not too stupid to care and not too bright to figure it out quickly.
Ah, mediocrity. Does that put me in the middle of the bell curve?
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #13 on: Sun, 07 June 2009, 12:44:42 »
Forgot to mention, the modifier keys can be listed like this:

anthony@anthony:~$ xmodmap -pm
xmodmap:  up to 3 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x25)
control     Control_L (0x42),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

not sure yet how that all works and how they can be called
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline nvarsj

  • Posts: 24
emulating the HHKB on a standard keyboard (linux)
« Reply #14 on: Sat, 11 July 2009, 21:59:00 »
Sorry to necro a 4 week old post. I'm pretty interested in trying this out on Linux as well.

xmodmap is a bit confusing but it's the way to accomplish this. You can do it with the Mode_switch key. For example, to turn my caps into Mode_switch (aka "fn" on hhkb) and bind Caps+s to Down:
Code: [Select]

keysym 66 = Mode_switch
keycode 39 = s S Down


Third key is what gets generated when pressed with Mode_switch. Second is with shift.

I'm going to work on setting this up, only problem is different keyboards seem to generate different keycodes (mostly just for control/alt/super), so it may not work for others.
HHKB2

Offline nvarsj

  • Posts: 24
emulating the HHKB on a standard keyboard (linux)
« Reply #15 on: Sat, 11 July 2009, 22:49:09 »
Ok, I've made a decently functioning xmodmaprc for linux. Just run 'xmodmap hhkb-xmodmaprc.txt' and it should work. Control and alt keys at bottom may be wrong, you can change the keycodes appropriately (use xev to see the keycodes).

I bound shift to "Fn". I think this emulates the location on the HHKB the best. However you may get frustrated having no right shift - I know I am. :P
HHKB2

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #16 on: Wed, 15 July 2009, 17:23:58 »
nvarsj, great work. I just got around to looking at it and made some changes.
I put the function key on the left windows key and put left alt back. I put /| where the backspace key is and put ~` where escape is up in the far left.

I am really liking that page up/down, home/end are working just like the hhkb.

Thanks much for contributing, great job!

see attached for the changed I made

HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline nvarsj

  • Posts: 24
emulating the HHKB on a standard keyboard (linux)
« Reply #17 on: Wed, 15 July 2009, 21:43:31 »
It feels pretty nice. The only weirdness to me is not having the arrow keys be an inverted T shape. A bit unfortunate they chose a diamond shape. If it was an inverted T I might just be tempted to by an HHKB... Although I probably will buy one at some point anyways.
HHKB2

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #18 on: Thu, 16 July 2009, 04:13:41 »
I had gotten used to the layout of the hhkb so the diamond layout isn't really a problem for me. The fnc + wasd might be interesting to try out though.
It's kind of funny, now that I can emulate the key pattern of the hhkb I no longer need to actually have the hhkb. I think I liked the hhkb layout more then I liked the topre keys.
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline xsphat

  • Posts: 2371
  • Location: 'Sconi FTW
  • Enlightened
    • Dan Newman, Writer
emulating the HHKB on a standard keyboard (linux)
« Reply #19 on: Thu, 16 July 2009, 04:34:18 »
HHKB Pro haters.

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #20 on: Thu, 16 July 2009, 12:40:40 »
Its also nice to emulate the hhkb layout on other keyboards, especially if you already have an hhkb and do like the layout. Using wasd for the arrow keys sounds interesting but would want the function key on the right windows key I think. I will try that out and post the config.
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline Rajagra

  • Posts: 1930
emulating the HHKB on a standard keyboard (linux)
« Reply #21 on: Thu, 16 July 2009, 13:44:04 »
Quote from: ripster;102870
Eiiti Wada - designer of the HHKB
Show Image


Tsk. It's Stephen Hawking's athletic younger brother showing off to the ladies again. Poor Steve, always getting his nose rubbed in it.

Just how old is the HHKB layout? I would have thought WASD, or at least the inverted T predated it.

I found one guy who hates the T layout.

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #22 on: Thu, 16 July 2009, 13:49:40 »
ripster, did you map LCTRL to the caps lock key or is it in the lower left hand corner?
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #23 on: Thu, 16 July 2009, 14:32:31 »
maybe not a lot of innovation if only because the original idea was so good?
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #24 on: Thu, 16 July 2009, 17:06:28 »
I got the wasd programmed and I am using the right windows key as the function key. I am trying out fnc + e for page up and fnc+f for page down. Still playing with it but not sure where to put home and end.
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #25 on: Thu, 16 July 2009, 17:48:12 »
this is more than I wanted to do, but maybe a visual will help.

HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #26 on: Thu, 16 July 2009, 19:40:08 »
I found the keyboard pic doing a google search and I used the gimp to modify it.
Having the xmodmap file so kindly provided makes life much easier. Its simple to edit and implement now.
I used to be dismissive of the windows key, now it is actually useful to me.
My model m mini's just cried a little bit.

Whats nice is that I can dial it in to exactly what I want. I suppose you can do the same with autohotkeys on windows.

Being able to do this now makes the hhkb much less valuable to me now. sigh.

brown cherries are the most sublime keys going.
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #27 on: Thu, 16 July 2009, 19:54:12 »
hey man, be nice or face the wrath of the topre gang : )

just to distance myself from the above mentioned heretic; I have to say the HHKB is a great keyboard. Great key layout in a small form factor and the topre keys are very nice too.

But yeah, once you can emulate the layout its game over. I now have 3 sets of arrow keys, the wasd setup, the hhkb setup and the existing arrow keys that already exist. Thats pretty sweet.
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII    

Offline bigpook

  • Thread Starter
  • Posts: 1723
emulating the HHKB on a standard keyboard (linux)
« Reply #28 on: Thu, 16 July 2009, 20:22:49 »
Heres the original picture of the keyboard

click me
HHKB Pro 2 : Unicomp Spacesaver : IBM Model M : DasIII