Author Topic: Dual-role keys  (Read 52370 times)

0 Members and 1 Guest are viewing this topic.

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Dual-role keys
« on: Tue, 26 March 2013, 02:09:10 »
Dual-role key works as modifier, Fn(layer switch) or other function when you hold it while normal key when you press and release it quickly. With this trick you can have two function on one physical key.

http://en.wikipedia.org/wiki/Modifier_key#Dual-role_keys

This video demonstrates my implementation of dual-role keys on Poker cursor keys. This setup places Up on Shift, Left on Alt, Down on Super and Right on Control.


Any other useful idea, tool or resourse?


Implementations:
* TouchCursor [WIN] (http://touchcursor.sourceforge.net/)
* xcape[X11] (https://github.com/alols/xcape)
* lydell's dual[AHK] (https://github.com/lydell/dual)
* BigCtrl[AHK] (https://github.com/benhansenslc/BigCtrl)
* Space 2 Control[X11] (https://github.com/r0adrunner/Space2Ctrl)
* At home modifier[X11] (https://gitorious.org/at-home-modifier/pages/Home)
* Karabiner[Mac](https://pqrs.org/osx/karabiner/) - KeyOverlaidModifier
* keydouble[X11](https://github.com/baskerville/keydouble)
* tmk firmware Tapping[AVR] (https://github.com/tmk/tmk_keyboard/blob/master/doc/keymap.md#4-tapping)
* evdev-spacefn[X11/evdev] (http://www.ljosa.com/~ljosa/software/spacefn-xorg/ https://geekhack.org/index.php?topic=51069.msg2540818#msg2540818)

Ideas:
* SpaceFN layout - suggested by spiceBar
* Shift/Space on Space - known as SandS in Japan
* Control/Backspace on Caps Lock
* Control/Esc on Caps Lock    (stevelosh.com)
* (/LShift and )/RShift    (stevelosh.com)
* Mods on home row


Resources:
* Matias one-handed keyboard uses similar technique(paper '96) - product page: half keyboard
« Last Edit: Thu, 28 December 2017, 19:33:09 by hasu »

Offline automator

  • Posts: 9
Re: Dual-role modifier keys
« Reply #1 on: Tue, 26 March 2013, 07:23:00 »
Cool... do you notice a lag on arrow?  I assume it doesn't register until keyup.

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #2 on: Tue, 26 March 2013, 08:09:18 »
You are right. There is actually a lag and it is noticeable if you care but no problem on normal text edit, I think.

Repeating will be rather a problem for most people. You must do tap and hold dual-role key to get auto repeat instead of just hold.

Offline SmallFry

  • ** Moderator Emeritus
  • Posts: 3887
  • Location: Wisconsin, USA
  • Leaving 6/15; returning 6/22 or so.
Re: Dual-role modifier keys
« Reply #3 on: Tue, 26 March 2013, 09:41:45 »
How do you implement this in your firmware, or is it computer based?

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #4 on: Tue, 26 March 2013, 12:09:56 »
It is implemented in firmware and configurable with keymap, because I like to have OS independent configuration in keyboard itself instead of setup on each machine.

You can find some software tools support this trick in the wikipedia page. I think keyremap4macbook also supports a kind of this feature. AHK can be used to implement this, of course.

Offline eon

  • Posts: 79
  • Location: France - Brittany
Re: Dual-role modifier keys
« Reply #5 on: Tue, 26 March 2013, 12:35:18 »
Very cool

So is it possible to modify the poker firmware ? Or I didn't understand a thing  :-\
Poker MX Red - Photos

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #6 on: Tue, 26 March 2013, 12:48:15 »
Sorry, I wasn't clear. I used prototype of GH60 with Poker keycaps and case in the video.
Stock Poker is not programmable so you can't modify its firmware.

Offline esoomenona

  • Gnillort?
  • Posts: 5323
Re: Dual-role modifier keys
« Reply #7 on: Tue, 26 March 2013, 12:50:38 »
Mhm, mhm. Bring on the GH60s!

Offline SmallFry

  • ** Moderator Emeritus
  • Posts: 3887
  • Location: Wisconsin, USA
  • Leaving 6/15; returning 6/22 or so.
Re: Dual-role modifier keys
« Reply #8 on: Tue, 26 March 2013, 13:27:45 »
How is it implemented in the firmware, for example, how do I set it up in your firmware?

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #9 on: Tue, 26 March 2013, 13:59:40 »
If you are interested in implementation source is available on github. https://github.com/tmk/tmk_keyboard

This part of my keymap.c. To define dual-role mod key use ACTION_RMOD_TAP_KEY. Not documented yet.
https://github.com/tmk/tmk_keyboard/blob/master/doc/keymap.md

Code: [Select]
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    KEYMAP_ANSI(
        ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC, \
        TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSLS, \
        LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   FN2, QUOT,     ENT,  \
        LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, FN1,           FN12, \
        LCTL,LGUI,LALT,          SPC,                     FN13,FN9, FN10,FN11),
};

static const uint16_t PROGMEM fn_actions[] = {
    [9] = ACTION_RMOD_TAP_KEY(KC_RALT, KC_LEFT),
    [10] = ACTION_RMOD_TAP_KEY(KC_RGUI, KC_DOWN),
    [11] = ACTION_RMOD_TAP_KEY(KC_RCTL, KC_RIGHT),
    [12] = ACTION_RMOD_TAP_KEY(KC_RSFT, KC_UP),
}
« Last Edit: Tue, 26 March 2013, 14:05:19 by hasu »

Offline SmallFry

  • ** Moderator Emeritus
  • Posts: 3887
  • Location: Wisconsin, USA
  • Leaving 6/15; returning 6/22 or so.
Re: Dual-role modifier keys
« Reply #10 on: Tue, 26 March 2013, 14:02:06 »
Danke! Will try this out later.

Offline eon

  • Posts: 79
  • Location: France - Brittany
Re: Dual-role modifier keys
« Reply #11 on: Wed, 27 March 2013, 05:00:01 »
Will definitively try this out when I have my GH60.

Thanks hasu
Poker MX Red - Photos

Offline ComradeSniper

  • HHKB Pro
  • * Esteemed Elder
  • Posts: 1086
  • Location: Seattle, WA
Re: Dual-role modifier keys
« Reply #12 on: Wed, 27 March 2013, 18:09:11 »
That is really cool. Now I want a GH60 even more.

Offline islisis

  • Posts: 120
  • Location: Tokyo, Japan
Re: Dual-role modifier keys
« Reply #13 on: Sun, 07 April 2013, 09:24:33 »
I really would love to see how dual role modifiers perform programmed in a microcontroller. I have spent some time prototyping variations in AHK, and implementing them properly in Linux is one of my big future goals. So, here I am posting my manifesto.

A lot of the functions I am using are tied with OS interface, but there are obviously common issues worth discussing:

1. A major one being, how do you deal with rollover? It is natural for multiple keys to be held down while typing quickly, without the intention for triggering a chord. AHK seems to handle an endless number of key remaps very effectively, so I am able to actually remap every single key to
  a) detect if D-R mod key is held
  b) 'sleep' for 70ms, and detect if D-R mod key is still being held
  c) if yes, overwrite key function with modifier layer
  d) else, perform original key function
(in addition to buffering input of the original D-R function to ensure the correct order of keypresses)

Sorry if this is explicit in your code, but I thought I would ask for some ideas in English (well, Japanese is okay too but :P)

If this were to be a mainstream implementation, what are the foreseeable issues which experienced and laypeople alike might encounter? Personally, I think achieving this sort of behaviour in software, let alone an interpreted script, will always leave it open to conflicts when CPU(s) are held up. However, in my mind this is a compromise worth taking for a lot of users. I plan to spend a lot of time researching possibilities for a mainstream implementation.

2. I don't think spacebar is good for a D-R key at all for this reason (in addition to upstroke activation being too annoying), even though it is clearly the most popular candidate and definitely useful in many specific scenarios. Likewise, I believe common alphanumeric keys should be excluded in default layouts - chorded keyboards should be classed in a separate use category from mainstream/downstroke activated keyboards, otherwise confusion/feel will forever prevent its acceptance. In the case of a kinesis-style mapping, backspace (left thumb) works very well. Tab is another good candidate (capslock also, but often reserved as dedicated ctrl). An actual kinesis/ergodox can use capslock, home, end (del also, but better as a dedicated mod key) - for the left side alone. On the right side, ralt, ' and \ are natural candidates.

3. Auto-repeat (see next post)

4. As for usage ideas, my position is that any layer function that is truly invaluable deserves a dedicated non D-R modifier key, because of the issue in 1. Therefore I treat any D-R layer as a 'convenience' layer. You can put in some useful highlight+copy/cut/paste style editing macros in there. Window functions like ctrl(shift)-tab, virtual desktop switching. Mouse functions can be vital to alleviate RSI. If you could make a quick record/play text macro function bindable to number keys etc that would be great. When combined with software mapping, mouse gestures, per application shortcuts, and much more. Even a simple alias for ctrl+alt+shift has its uses. On the kinesis/ergodox I count >600 accessible global shortcuts - for the LHS alone. I am currently testing use of ~120 LHS shortcuts.

5. In the end the most important problem is standardisation. This will mean common functions will take a long time time to emerge from the community's choices. Related issues apply to the mouse button equivalent also, rocker gestures. One which incorporates some smart mnemonics will likely prove the winner. So, it's worth discussing imho.

Anyhow, looking forward to see what hardware functions you guys come up with.
« Last Edit: Fri, 24 May 2013, 00:50:40 by islisis »

Offline islisis

  • Posts: 120
  • Location: Tokyo, Japan
Re: Dual-role modifier keys
« Reply #14 on: Sun, 07 April 2013, 09:33:26 »
Repeating will be rather a problem for most people. You must do tap and hold dual-role key to get auto repeat instead of just hold.

There is this issue also. Personally I don't find auto-repeat necessary so I have it disabled, but before that I let the mod key wait a timeout period for another key to be pressed. If the timeout was reached while still being held down, it would repeat.

It's much more useful for me to have it auto-cancel the original key function after the timeout instead, because accidental (read "I changed my mind" aka "I just enjoy pressing random modifier keys") presses are an obvious issue I should have stated. Alternatively you can set a follow-up 'cancel key'. I guess that you sensed this also, and so implemented a separate method for auto-repeat. Sounds good.

Finally, I'm going to take the liberty of an off-topic rant/question here: is there no plan for a JP layout of the GH60? Because, for reasons including the topic of this thread, I would like to see thumb modifiers a widespread option for keyboards in the future.
« Last Edit: Sun, 07 April 2013, 10:34:49 by islisis »

Offline Findecanor

  • Posts: 5036
  • Location: Koriko
Re: Dual-role modifier keys
« Reply #15 on: Sun, 07 April 2013, 10:18:35 »
Dual-role mod works as modifier when you press and hold it but as other normal key when you tap.
I have been thinking about something that is slightly different that would take this further: combine the Alt and Fn keys.
The reasons why are 1) there are so few key combinations with Alt in the programs that I use, but the few that I use, I use very often. 2) I want to minimise my number of modifiers. I have also Shift, Control and Alt Graph.

When you press and release the Fn/Alt-key it would produce a quick tap and release of the Alt key, but if you hold it and press another key it would enable Fn-layer.
However, you would also be able to map a key combination with Alt, such as "Alt-Tab" to a key on the Fn-layer.
If you press Fn/Alt, then Tab and then release Tab, it would register as holding the Alt key as long as you hold down the Fn/Alt key, but the active layer should still remain the Fn-layer. If you now press another key, then its symbol on the Fn-layer would register as pressed together with Alt.

The problem I have is selecting a simple and consistent policy for how the mechanism should work. Should there only be a "bit" on the key on the Fn-layer that would activate the Alt symbol or should there be support for all kinds of modifier combinations on a key?
For instance, should I be able to map a combination with Control to a key on the Fn-Layer and should the Fn/Alt key then be temporarily assigned to Control?
« Last Edit: Mon, 08 April 2013, 08:28:57 by Findecanor »

Offline n0rvig

  • Posts: 355
Re: Dual-role modifier keys
« Reply #16 on: Sun, 07 April 2013, 12:01:08 »
Nice! This is exactly what makes the GH60 so exciting! I'm looking forward to having CAPS-LOCK remapped to CTRL / ESC in hardware for Vim.

I've been meaning to setup dual-role modifier keys ever since I read Steve Losh's modern space-cadet post.
http://stevelosh.com/blog/2012/10/a-modern-space-cadet/

Offline hoggy

  • * Ergonomics Moderator
  • Posts: 1502
  • Location: Isle of Man
Re: Dual-role modifier keys
« Reply #17 on: Sun, 07 April 2013, 14:59:25 »
I think Steve Losh's idea of re-using the shift keys for ( and ) is simply genius.
GH Ergonomic Guide (in progress)
http://geekhack.org/index.php?topic=54680.0

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #18 on: Sun, 07 April 2013, 22:56:21 »
islisis, hey.
It is uncommon to see and discuss with other Japanese member on this forum :D It is fun!

As for repeat and cancel thing I totally agree with you. In fact cancel is more useful or important than repeat. In my firmware I use 200ms for timeout. I can cancel a key with holding during the term.
I'll read and reply with your another post later.
                                                             
Off-topic is a fun part and nature of this forum :)                                               
I think GH60 supports JIS layout except bottom row. But we need more thumb keys, right? I'm not a fan of space and mods of JIS, instead I prefer split of space bar like Erase Eaze.   
http://geekhack.org/index.php?topic=41724.msg841006#msg841006


Repeating will be rather a problem for most people. You must do tap and hold dual-role key to get auto repeat instead of just hold.

There is this issue also. Personally I don't find auto-repeat necessary so I have it disabled, but before that I let the mod key wait a timeout period for another key to be pressed. If the timeout was reached while still being held down, it would repeat.

It's much more useful for me to have it auto-cancel the original key function after the timeout instead, because accidental (read "I changed my mind" aka "I just enjoy pressing random modifier keys") presses are an obvious issue I should have stated. Alternatively you can set a follow-up 'cancel key'. I guess that you sensed this also, and so implemented a separate method for auto-repeat. Sounds good.

Finally, I'm going to take the liberty of an off-topic rant/question here: is there no plan for a JP layout of the GH60? Because, for reasons including the topic of this thread, I would like to see thumb modifiers a widespread option for keyboards in the future.

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #19 on: Sun, 07 April 2013, 23:04:37 »
Findecanor,                                                                                       
to be honest it is not clear your idea to me.
As you know dual-role modifier basically handles a modifier(including Fn) and a normal key, it won't work on a combination of two modifiers like Alt and Fn. I couldn't get how to discriminate those Alt and Fn from your explain. Can you describe more actual example of keymap or layer you want to define?

n0rvig, hoggy,
I added them on my first post for reference. Thank you!

Offline hoggy

  • * Ergonomics Moderator
  • Posts: 1502
  • Location: Isle of Man
Re: Dual-role modifier keys
« Reply #20 on: Mon, 08 April 2013, 04:31:23 »
There's also the old classic of shift and space.

Press and release the space bar for space, space bar and a for A.
GH Ergonomic Guide (in progress)
http://geekhack.org/index.php?topic=54680.0

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #21 on: Mon, 08 April 2013, 11:52:53 »
I really would love to see how dual role modifiers perform programmed in a microcontroller. I have spent some time prototyping variations in AHK, and implementing them properly in Linux is one of my big future goals.
Can you post your AHK scripts somewhere like gist/pastbin to share? They will be useful for someone to start this.


Quote
1. A major one being, how do you deal with rollover? It is natural for multiple keys to be held down while typing quickly, without the intention for triggering a chord. AHK seems to handle an endless number of key remaps very effectively, so I am able to actually remap every single key to
  a) detect if D-R mod key is held
  b) 'sleep' for 70ms, and detect if D-R mod key is still being held
  c) if yes, overwrite key function with modifier layer
  d) else, perform original key function
(in addition to buffering input of the original D-R function to ensure the correct order of keypresses)

Sorry if this is explicit in your code, but I thought I would ask for some ideas in English (well, Japanese is okay too but :P)

If this were to be a mainstream implementation, what are the foreseeable issues which experienced and laypeople alike might encounter? Personally, I think achieving this sort of behaviour in software, let alone an interpreted script, will always leave it open to conflicts when CPU(s) are held up. However, in my mind this is a compromise worth taking for a lot of users. I plan to spend a lot of time researching possibilities for implementation.
I use key event buffer whose size is 8(*6byte) atm to keep events while DRmod key is undetermined yet.
Rules determining whether DRmod should perform as key or modifier are very simple:
1. Judging term (200ms in my case) elapsed(timeout) => modifier
3. DRmod is released within 200ms(tapping)  => key
Rules are simple but implementation will be a bit complex to handle some exceptional case. Looks like memory space and CPU cycles needed by my code are reasonable and no problem on AVR controller.

What is your problem about 1. actually? Erroneous decision of whether key or mod? I think you may be able to improve it much with tweaking code and parameters for your preference.
I have improved my code gradually for two years including rewriting from scratch and now happy with it.


Quote
2. I don't think spacebar is good for a D-R key at all for this reason (in addition to upstroke activation being too annoying), even though it is clearly the most popular candidate and definitely useful in many specific scenarios. In the case of a kinesis style mapping, backspace (left thumb) works very well. Tab is another good candidate. The kinesis also can also use capslock, pgup, pgdn - for the left side alone.
It depends on your type speed and style. I have had layer switch feature on space bar for about two years and erroneous decision is very rare with my latest implementation. But I'm a slow typist and don't type much daily. Of course, you don't have to use space bar if you have another options.

« Last Edit: Mon, 08 April 2013, 11:54:31 by hasu »

Offline hoggy

  • * Ergonomics Moderator
  • Posts: 1502
  • Location: Isle of Man
Re: Dual-role modifier keys
« Reply #22 on: Mon, 08 April 2013, 13:19:33 »
Someone on superuser.com worked this up for me.

LShift UP::Send, (
RShift UP::Send, )
LShift & F13::
RShift & F13::

GH Ergonomic Guide (in progress)
http://geekhack.org/index.php?topic=54680.0

Offline islisis

  • Posts: 120
  • Location: Tokyo, Japan
Re: Dual-role modifier keys
« Reply #23 on: Mon, 08 April 2013, 16:04:14 »
edit: re-reading your explanation, I think we both solve the issue of DR decision - if I now understand correctly, after the DR mod is pressed you use a buffer to hold subsequent keystrokes until 200ms has passed, or the DR mod key is released; this sounds optimal to me, I'm sure it works great. In my example I wait 70ms.

I am glad to finally see this taken into consideration because such a buffer is absent in many implementations. Having it in microcontroller is a really good option, script is the worst. Posting my AHK script would not make the issue any clearer (AHK is also not optimal for DR rollover detection, for instance I originally wanted to implement it your way but it doesn't seem possible). I will explore the options to implement it efficiently in software for a mainstream release, and that will mean Linux.

Also I would be interested to hear what key functions you have found useful over your 2 years of testing!

It is uncommon to see and discuss with other Japanese member on this forum :D It is fun!

I think it is more uncommon to see Japanese people with English as good as yours! That may be the reason. I can speak Japanese and live here, but I'm not Japanese myself!

I think GH60 supports JIS layout except bottom row. But we need more thumb keys, right? I'm not a fan of space and mods of JIS, instead I prefer split of space bar like Erase Eaze.   
http://geekhack.org/index.php?topic=41724.msg841006#msg841006

The more thumb keys the better, in my opinion :D So a split space bar is great. The JIS layout is a standard, however, which makes it easier for people find keyboards for. This is why I thought it could be an option for GH60 as well :/ Of course custom is better for us!
« Last Edit: Mon, 20 May 2013, 09:21:25 by islisis »

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #24 on: Mon, 08 April 2013, 23:09:23 »
Thanks for your explanation hasu! I could have examined your code, but now I think I understand your implementation. The issues I described are related to instant registering of DR mod key presses. In your case, the user's intention is unambiguous because they will first have to wait 200ms before the modifier is registered. Other implementations, including mine and the also code pasted by hoggy, don't register DR in the same way - registration starts instantly as soon as the DR and target keys are rolled-over. Personally I find this action is desirable because then I can use DR chords in the same way as standard modifier chords.

Ah, other implementations works that way? Looks like I should look into other tools for detail of implementation. I didn't come up with that optimization and I for one didn't find need of that. I don't find that lag on my normal usage but other may bother it.

In my implementation you don't have to wait 200ms for typing next key but you have to hold the DRmod key for 200ms at least. If you release the key before that you get a key function. I believe this behavior is need for better roll-over support.
I'm willing to admit that fast typist will suffer from this limitation even though the time parameter is configurable.

Which optimization method is better seems to  depend on whether you use a DRkey mainly as key or mod. I use my DRkeys(; / space) as key than mod and my implementation is optimized for that.

Seems like we need configurable option to select favorite optimization methods.


Quote
In the instant case, however, as I have explained a commonly used key like space this will cause issues for any typer eventually, because even a millisecond of overlapping keypresses will trigger the DR layer. This is why I am surprised not to see it mentioned in many discussions.
To avoid this false detection I believe we need the inevitable lag time in the end. And I think my firmware works well on this thing. To get space you are only required to type a key with the timeout period, this is very easy to fulfill.

Two optimization policies(key first/mod first) seems to be incompatible each other. I think we can get way better result using proper policy.


Simple AHK script hoggy posted above is good for start point, but it doesn't has any optimization. So it suffers from this problem. Also it has no cancel/timeout feature.
With the script if you type LShift, A and RShift quickly to get '(a)',  you will get 'A)'.






Quote
Sorry for causing the confusion, I hope my intention for discussion is clear now >_< Also I would be interested to hear what key functions you have found useful over your 2 years of testing!
I've used mainly 'semicolon' for mousekey layer, 'space' for second mousekey layer and 'slash' for cursor key layer. Recently I started using RShift  for `(grave) on my proto GH60.
I have almost no problem on these keys now, but they are less used relatively compare to alpha keys.
Now I have a plan for testing dual-mod key on home row keys like asdfjkl to see how my implementation goes under harsh environment :D


Quote
It is uncommon to see and discuss with other Japanese member on this forum :D It is fun!

I think it is more uncommon to see Japanese people with English as good as yours! That may be the reason. I can speak Japanese and live here, but I'm not Japanese myself!
Haha, I tend to jump to (wrong) conclusions :)


Offline islisis

  • Posts: 120
  • Location: Tokyo, Japan
Re: Dual-role modifier keys
« Reply #25 on: Mon, 08 April 2013, 23:26:44 »
Sorry hasu I re-read your explanation tried to edit my post before you saw it, but was too late!

Ah, other implementations works that way? Looks like I should look into other tools for detail of implementation. I didn't come up with that optimization and I for one didn't find need of that.

No, ignore my statement - I first thought that target keys would be ignored during the 200ms period, but then I saw that your implementation will use a buffer to detect keypresses, so the result is the same. I think your method is best, sorry again for the confusion!

And you are right that hoggy's example has no buffer implementation. It's not easy to do in AHK.

edit:
Thanks for your examples, I see I need to research much more and am amazed by how useful your full firmware is. I am interested in software implementation, so I will research methods for invoking arbitrary numbers of modifier keys, hopefully to achieve what you already have!
« Last Edit: Tue, 09 April 2013, 05:48:26 by islisis »

Offline lydell

  • Posts: 42
  • Location: Sweden
Re: Dual-role modifier keys
« Reply #26 on: Sat, 18 May 2013, 16:40:30 »
I've been using BigCtrl (AHK script) for a few months, and it has worked very well. It combines space and control, and uses timeouts to prevent mistakes (and does it well!).

Today I realized that one could take this one step further: Not only make modifier keys also into normal keys—but normal keys also into modifier keys! I'm thinking about putting modifier keys on the home row, for example, say, shift on the index fingers. Sounds awesome to me, I just have find the time to learn AHK … (but BigCtrl is good starting point I guess). Has anyone tried this before?

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #27 on: Sat, 18 May 2013, 19:19:09 »
I'll add a link to BigCtrl on first post, it looks like a clean, concise and well documented code, it'll be good for starting point. I didn't know this tool yet. Thanks.

Placing modifiers on home row is nice idea. I've used ';' as modifier happily for a few years but never tried other home keys. If you use alpha keys as modifier it'll be important to choke off false detection as possible with tweaking code or parameters. It is really challenging idea.

Offline lydell

  • Posts: 42
  • Location: Sweden
Re: Dual-role modifier keys
« Reply #28 on: Thu, 04 July 2013, 17:45:17 »
I've made some progress on implementing dual-role keys with AutoHotkey. It was a lot harder than I expected … I will now start experimenting with dual-role home keys. I'll report back when I have more experience.

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #29 on: Fri, 05 July 2013, 05:55:31 »
Wow, great work!
I read through readme, very nice write up too!
This make me find new issue I've missed so far, which is "bob" case of DoublePress. Hmm, look like I need to work this case on my firmware.

And I'll try your ahk script later when I'm back on windows.

Offline lydell

  • Posts: 42
  • Location: Sweden
Re: Dual-role modifier keys
« Reply #30 on: Sun, 01 September 2013, 14:21:16 »
So … it's been two months, and I said that I should report back. Here are some experiences:

First off, I have not used dual-role modifiers for two months! Why? Because it has been a nightmare to implement. Countless times I have thought that I've nailed it, but a few minutes of real usage has usually been enough to find it totally unusable: There has always been some quirk killing all the pros of dual-role keys. I guess it is a combination of having bad programming days, being quite new to AHK, quirks of AHK, and that dual-role keys actually are difficult to implement. This has been very frustrating, and therefore I lost the motivation to work on it for periods of time. Moreover, I have had more to do than hacking on keyboards ;)

However, three days ago I finally came up with a version (0.3.1) of my AHK script that I actually could use. In just a few days I have grown to absolutely love it! And after fixing a very annoying bug today (making characters output in backwards order), it works really smoothly.

For the moment, I have put shift on the index fingers, control on the middle fingers and alt on the ring fingers, all on the home row. Then I have the Windows keys on the middle fingers in the top row.

At first I almost could not stand the lag introduced by the characters appearing on keyup, but now I almost don't notice it. It is totally worth the lag having the modifiers in such convenient spots. It is super easy to press for example control-shift-alt-x now.

One thing that really made a big difference in my script, is the ability to have key-level settings (which I added in version 0.3.0). I use 70ms delay by default, and 200ms for the alt and Windows dual-role keys.

Offline Findecanor

  • Posts: 5036
  • Location: Koriko
Re: Dual-role modifier keys
« Reply #31 on: Tue, 10 September 2013, 06:49:54 »
to be honest it is not clear your idea to me.
As you know dual-role modifier basically handles a modifier(including Fn) and a normal key, it won't work on a combination of two modifiers like Alt and Fn. I couldn't get how to discriminate those Alt and Fn from your explain. Can you describe more actual example of keymap or layer you want to define?
I'm sorry, I had forgotten about this until a similar idea came up in another thread which reminded of this.

What I want is this:
If you press Fn-Tab, it should emit Alt-Tab.
However, for proper Windows-style Alt-tabbing to work, it should also support cases of holding Fn and pressing Tab repeatedly. The alt-tabbing panel should be visible for as long as you continue holding Fn.

What happens on pressing the Tab on the Fn layer is:
1. The Fn keypress is exchanged with an Alt keypress in the table of pressed keys. (Any firmware that supports multiple layers should store the full symbol and not just a bit in this table or it would not correctly support holding a key down while changing layers)
2. Both "Alt" and "Tab" are pushed on the event queue. (if your USB firmware just scans the table of pressed keys, this should not be needed ... but you would need an event queue of some sort to correctly handle the case when the number of pressed keys exceeds the interface's limit)
3. The current layer should revert to the layer it was on before the Fn key was pressed.

Offline Findecanor

  • Posts: 5036
  • Location: Koriko
Re: Dual-role modifier keys
« Reply #32 on: Tue, 17 September 2013, 19:56:46 »
About ordinary dual-role modifier keys (not the weird one I mentioned above):

Why is it necessary to have a delay?
Would it not suffice to just check if the key is used together with another key, or released after not having pressed another key?

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #33 on: Wed, 18 September 2013, 00:19:52 »
Think of a dual-role key is comprised of Space and Shift.
 
When you type, for example, "a man" fast you will/may press 'm' before releasing space key.
Without the delay you will get "aMan" in this case.

If you release space key within the delay it registers Space, if not it works as Shift, my firmware does a job like this basically.
« Last Edit: Wed, 18 September 2013, 00:22:42 by hasu »

Offline jalli

  • Posts: 101
  • Location: Toronto, Canada
Re: Dual-role modifier keys
« Reply #34 on: Wed, 18 September 2013, 20:22:19 »
I'm really happy this thread got revived, I've been thinking exactly along these lines for my new Global Ergodox Latin keyboard (Gelatin).

Basically I'm in a situation where I frequently need to use non-ASCII latin characters found in non-English Euro languages, switching between multiple layouts is a pain and I also want a Colemak style optimized keyboard, unfortunately AltGr+t+y is not a usable pattern to write in every other sentence.

Hence I started thinking about having the modifiers double as dead keys

Basically, shift would be a dead key for upper case (so that you don't have to hold it down while pressing the Alpha key)

Each of the other modifiers would become a modifier to allow characters such as åáíúæþý to be written, same keyboard layout for all Latin character languages with a fully optimized pattern..

Example to sum up:

Ctrl Down is recorded, no signal is sent to the PC.
If another key is pressed before Ctrl is released, send Ctrl down and other key. any subsequent keys pressed/released are sent immediately including the Ctrl key being released.
If Ctrl is released without any other key press, send dead key scan code to PC.

Using modifiers as dead keys:
http://geekhack.org/index.php?topic=45211.msg1038689#msg1038689

I think this should work for Ctrl, Alt, Shift, on both sides, on top of this I also had an idea on how to change the legends on the keys depending on which dead key/modifier has been pressed:

RGB Led multi legends:
http://geekhack.org/index.php?topic=48584.0;topicseen
Antonia

Offline spiceBar

  • Posts: 998
    • ChessTiger.com
Re: Dual-role modifier keys
« Reply #35 on: Wed, 06 November 2013, 05:38:56 »
This thread is very interesting, and it looks like a lot of work and of thoughts went into making dual-role modifier keys work.

I would like to know about your success in using space as a dual-role modifier.

At this point, can space be used reliably as a dual-role modifier?

I'm thinking about a 60% layout where space would be used instead of a traditional Fn key. Space is especially interesting and important because this key is always under our thumbs, and pressing it does not require any "aiming". It's a big target so easy to reach, that you can effortlessly hold space while hitting any other key on the keyboard, even with just one hand.

Naturally we have the problem of space being used so often in normal typing that accidental rollover of space + any other key happens all the time. But apparently you guys have dealt with this issue.

Do you guys think it is realistic to use space as an Fn key, or am I just dreaming?

Offline Matias

  • * Commercial Vendor
  • Posts: 517
  • Location: Toronto
    • http://matias.ca
Re: Dual-role modifier keys
« Reply #36 on: Wed, 06 November 2013, 06:39:35 »
This thread is very interesting, and it looks like a lot of work and of thoughts went into making dual-role modifier keys work.

I would like to know about your success in using space as a dual-role modifier.

At this point, can space be used reliably as a dual-role modifier?


Fortunately, this is a solved problem -- by me :) 20 years ago.  Man, time flies. :(

Anyway, you can read all about it here, including a technical description of how to implement it efficiently in code...

http://edgarmatias.com/papers/hci96

Basically, any key can be used as a dual modifier/non-modifier, as long as you're willing to lose the auto-repeat on that key.

I used this technique to implement a one-handed keyboard, embedded in a standard keyboard, but the general concept is useful for other things.  Back then, I called it the "flip operation".  If you want to try it, there's a flash demo here...

http://matias.ca/halfkeyboard/demo

You'll notice that if you press the spacebar fast enough, you don't notice the lag.

The trick to this is having a timeout value that's not too long and not too short.  It needs to be long enough to give you enough time to press & release the key when you want the non-modifier, but short enough to not generate stray keystrokes when you want the modifier mode.  I found that a 267-millisecond timeout (~1/4 second) was the sweet spot.


I'm thinking about a 60% layout where space would be used instead of a traditional Fn key. Space is especially interesting and important because this key is always under our thumbs, and pressing it does not require any "aiming". It's a big target so easy to reach, that you can effortlessly hold space while hitting any other key on the keyboard, even with just one hand.

Naturally we have the problem of space being used so often in normal typing that accidental rollover of space + any other key happens all the time. But apparently you guys have dealt with this issue.

Do you guys think it is realistic to use space as an Fn key, or am I just dreaming?


Actually, I think the way hasu did it is perfect.  Use the right Shift key within the timeout for Up arrow, OR press & hold it for Shift.  Perfectly intuitive.

Nice work hasu!

« Last Edit: Wed, 06 November 2013, 06:48:49 by Matias »

Offline jalli

  • Posts: 101
  • Location: Toronto, Canada
Re: Dual-role modifier keys
« Reply #37 on: Wed, 06 November 2013, 09:35:20 »
I've been playing around with the tmk firmware quite a bit recently and it has the ability to do pretty much all of this, unfortunately I'm still waiting for my Ergodox kit from Massdrop so I can't test anything but once I have everything up and running I'll post some examples.
Antonia

Offline spiceBar

  • Posts: 998
    • ChessTiger.com
Re: Dual-role modifier keys
« Reply #38 on: Wed, 06 November 2013, 10:37:46 »
This thread is very interesting, and it looks like a lot of work and of thoughts went into making dual-role modifier keys work.

I would like to know about your success in using space as a dual-role modifier.

At this point, can space be used reliably as a dual-role modifier?


Fortunately, this is a solved problem -- by me :) 20 years ago.  Man, time flies. :(

Anyway, you can read all about it here, including a technical description of how to implement it efficiently in code...

http://edgarmatias.com/papers/hci96

Basically, any key can be used as a dual modifier/non-modifier, as long as you're willing to lose the auto-repeat on that key.

I used this technique to implement a one-handed keyboard, embedded in a standard keyboard, but the general concept is useful for other things.  Back then, I called it the "flip operation".  If you want to try it, there's a flash demo here...

http://matias.ca/halfkeyboard/demo

You'll notice that if you press the spacebar fast enough, you don't notice the lag.

The trick to this is having a timeout value that's not too long and not too short.  It needs to be long enough to give you enough time to press & release the key when you want the non-modifier, but short enough to not generate stray keystrokes when you want the modifier mode.  I found that a 267-millisecond timeout (~1/4 second) was the sweet spot.


I'm thinking about a 60% layout where space would be used instead of a traditional Fn key. Space is especially interesting and important because this key is always under our thumbs, and pressing it does not require any "aiming". It's a big target so easy to reach, that you can effortlessly hold space while hitting any other key on the keyboard, even with just one hand.

Naturally we have the problem of space being used so often in normal typing that accidental rollover of space + any other key happens all the time. But apparently you guys have dealt with this issue.

Do you guys think it is realistic to use space as an Fn key, or am I just dreaming?


Actually, I think the way hasu did it is perfect.  Use the right Shift key within the timeout for Up arrow, OR press & hold it for Shift.  Perfectly intuitive.

Nice work hasu!

OK, great!

Coincidentally, my question stems from thoughts I had last night following an answer to the thread you have started about the 60% form factor! :)

I have already tried to design 60% layouts, and I have even tested some (I have tested 6 of them by simulating them in software).

Some time ago I have posted what I thought was one of the best, but it was not very well received, because I had moved ONE character (the slash):
  http://geekhack.org/index.php?topic=47888.msg1023617#msg1023617

Now I have a design that does not move any character, so it allows touch typists to feel at home, and does not even use all the keys of a 60%.

I would be delighted to share this with you by PM or in a dedicated thread, assuming you have the time and interest for this.

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role modifier keys
« Reply #39 on: Wed, 06 November 2013, 11:59:55 »
Matias, Thanks for heads up!
I couldn't find that paper when I looked into your Half-Keyboard. Great resouce! and also historical :) I added it to first post of this thread. Again, I love your half-QWERY idea. Yes, one of reasons I needed dual-role function is to implement my version of Half-keyboard.

Offline Matias

  • * Commercial Vendor
  • Posts: 517
  • Location: Toronto
    • http://matias.ca
Re: Dual-role modifier keys
« Reply #40 on: Thu, 07 November 2013, 09:54:29 »
Matias, Thanks for heads up!
I couldn't find that paper when I looked into your Half-Keyboard. Great resouce! and also historical :) I added it to first post of this thread. Again, I love your half-QWERY idea. Yes, one of reasons I needed dual-role function is to implement my version of Half-keyboard.

Glad to help.  :)


Offline Matias

  • * Commercial Vendor
  • Posts: 517
  • Location: Toronto
    • http://matias.ca
Re: Dual-role modifier keys
« Reply #41 on: Thu, 07 November 2013, 09:59:23 »
Coincidentally, my question stems from thoughts I had last night following an answer to the thread you have started about the 60% form factor! :)

I have already tried to design 60% layouts, and I have even tested some (I have tested 6 of them by simulating them in software).

Some time ago I have posted what I thought was one of the best, but it was not very well received, because I had moved ONE character (the slash):
  http://geekhack.org/index.php?topic=47888.msg1023617#msg1023617

Haa, I can certainly sympathize.  We had similar outrage from some users when released a keyboard that had the Caps Lock replaced by Ctrl.  You can't please everyone.  :)


Now I have a design that does not move any character, so it allows touch typists to feel at home, and does not even use all the keys of a 60%.

I would be delighted to share this with you by PM or in a dedicated thread, assuming you have the time and interest for this.

I'm always interested in new ideas.  If you post it in a thread, you'll gave the benefit of others' feedback as well.


Offline spiceBar

  • Posts: 998
    • ChessTiger.com
Re: Dual-role modifier keys
« Reply #42 on: Thu, 07 November 2013, 18:16:27 »
Coincidentally, my question stems from thoughts I had last night following an answer to the thread you have started about the 60% form factor! :)

I have already tried to design 60% layouts, and I have even tested some (I have tested 6 of them by simulating them in software).

Some time ago I have posted what I thought was one of the best, but it was not very well received, because I had moved ONE character (the slash):
  http://geekhack.org/index.php?topic=47888.msg1023617#msg1023617

Haa, I can certainly sympathize.  We had similar outrage from some users when released a keyboard that had the Caps Lock replaced by Ctrl.  You can't please everyone.  :)


Now I have a design that does not move any character, so it allows touch typists to feel at home, and does not even use all the keys of a 60%.

I would be delighted to share this with you by PM or in a dedicated thread, assuming you have the time and interest for this.

I'm always interested in new ideas.  If you post it in a thread, you'll gave the benefit of others' feedback as well.

OK, I'll post it in a new thread and brace myself for the outrage. :)

Offline jeffgran

  • Posts: 126
  • Location: Denver
Re: Dual-role modifier keys
« Reply #43 on: Sun, 17 November 2013, 15:29:37 »
This thread is very interesting, and it looks like a lot of work and of thoughts went into making dual-role modifier keys work.

I would like to know about your success in using space as a dual-role modifier.

At this point, can space be used reliably as a dual-role modifier?


Fortunately, this is a solved problem -- by me :) 20 years ago.  Man, time flies. :(

Anyway, you can read all about it here, including a technical description of how to implement it efficiently in code...

http://edgarmatias.com/papers/hci96

Basically, any key can be used as a dual modifier/non-modifier, as long as you're willing to lose the auto-repeat on that key.

I used this technique to implement a one-handed keyboard, embedded in a standard keyboard, but the general concept is useful for other things.  Back then, I called it the "flip operation".  If you want to try it, there's a flash demo here...

http://matias.ca/halfkeyboard/demo

You'll notice that if you press the spacebar fast enough, you don't notice the lag.

The trick to this is having a timeout value that's not too long and not too short.  It needs to be long enough to give you enough time to press & release the key when you want the non-modifier, but short enough to not generate stray keystrokes when you want the modifier mode.  I found that a 267-millisecond timeout (~1/4 second) was the sweet spot.


I'm thinking about a 60% layout where space would be used instead of a traditional Fn key. Space is especially interesting and important because this key is always under our thumbs, and pressing it does not require any "aiming". It's a big target so easy to reach, that you can effortlessly hold space while hitting any other key on the keyboard, even with just one hand.

Naturally we have the problem of space being used so often in normal typing that accidental rollover of space + any other key happens all the time. But apparently you guys have dealt with this issue.

Do you guys think it is realistic to use space as an Fn key, or am I just dreaming?


Actually, I think the way hasu did it is perfect.  Use the right Shift key within the timeout for Up arrow, OR press & hold it for Shift.  Perfectly intuitive.

Nice work hasu!

Thanks for posting this, Matias. This is a really great idea, and the opportunity to try it instantly with your flash demo lets you see how easy it really is and how well it works. I think I'm going to try to get this working (space, backspace, enter all as dual mod keys) on my ergodox. :)

Offline Matias

  • * Commercial Vendor
  • Posts: 517
  • Location: Toronto
    • http://matias.ca
Re: Dual-role modifier keys
« Reply #44 on: Sun, 17 November 2013, 15:49:19 »
Thanks for posting this, Matias. This is a really great idea, and the opportunity to try it instantly with your flash demo lets you see how easy it really is and how well it works. I think I'm going to try to get this working (space, backspace, enter all as dual mod keys) on my ergodox. :)

No problem.  :-)

BTW, while one-handed typing is very cool, I found that replacing Caps Lock with an Fn key (and a well designed Fn layer) is a lot more useful in day-to-day use...

http://matias.ca/optimizer

http://matias.ca/optimizer/viewer/?p=5

The Backspace, Enter, Copy/Paste shortcuts on the left hand are expecially handy.


Offline lydell

  • Posts: 42
  • Location: Sweden
Re: Dual-role keys
« Reply #45 on: Sun, 15 December 2013, 03:26:49 »
Now there's been yet another two months since my last post. Here are some more experiences with my modifiers on the home row experiment.

During most of the past two months, I've absolutely loved it. I've had to update my AHK script a few times though, to be able to tweak some things after a while. That's a downside of it: It requires a lot of fiddling to get it right.

However, the last week or so, it feels like I've hit the limit. Now, it is slowing me down. I trigger control shortcut keys way too often while typing, and sometimes the text gets all garbled up because of all timeouts and stuff.

So I've come to the conclusion that there are three things I like about modifiers on the home row:

* The pinky does not have to do everything.
* It's very easy to use multiple modifiers at the same time, since each modifier has its dedicated finger.
* They're always within reach.

I've now decided to ditch the last point, in favor of faster typing speed, by moving the dual-role modifiers two steps up to the number row. That's gonna be a bit longer reach, but the two other benefits remain. The experiment goes on...

During this time, I've also made space and enter into dual-role keys. I haven't had any problems with them, though. I think that the conclusion is that you shouldn't make character keys into dual-role keys.

Offline angelic_sedition

  • Posts: 124
  • Location: Flatland
Re: Dual-role keys
« Reply #46 on: Mon, 10 February 2014, 22:34:42 »
Too bad there is no good implementation on linux. For simple modifier to something on key release i.e. escape on caps tap, there's xcape (and similarly keydouble and space2ctrl), however there is no program that perfectly deals with with using "normal" keys as modifiers. The closest is AHM which at least tries to do something about accidental presses, but I had to stop using it because it doesn't work perfectly. If anyone knows of another solution while I try to get tmk firmware running, I'd be happy to hear it.

My conclusion is not that character keys shouldn't be made into dual role keys; I think they are the best candidates. I think a hybrid chording system has a lot of potential. With enough easily accessible thumb keys, I probably wouldn't use more than 1 or 2.. 4 max probably. In the past I've used qwerty d to access my nav/misc layer (things like backspace, arrows, a few symbols, tmux prefix key, etc.) and spacebar for window management, launching most used programs, and my most important hotkeys. I wonder how well remapping shift to a letter on each side would work. As for modifiers as normal keys, I only ever do escape on release.
QWERTY(104wpm) -> CarpalxQ(modded) -> Colemak(118wpm) -> Colemak-DH
Mouse less.

Offline plainbriny

  • Posts: 192
  • Location: Taiwan
Re: Dual-role keys
« Reply #47 on: Tue, 11 February 2014, 00:12:40 »
My use of dual role keys:

1. space as shift: we usually don't press space and shift at the same time, this setting helps to keep my hands on the home row

2. f used to activate navigation layer: I have a layer in which the right hand home row keys are assigned to navigation keys, since we seldom use characters and navigation keys (arrow keys) in combination, this setting allows me to keep my hands on the home row all the time 

I have been using tmk firmware for a couple of months, this firmware is amazing. I will never consider non-programmable keyboards again.

Offline spiceBar

  • Posts: 998
    • ChessTiger.com
Re: Dual-role keys
« Reply #48 on: Tue, 11 February 2014, 06:42:23 »
Too bad there is no good implementation on linux. For simple modifier to something on key release i.e. escape on caps tap, there's xcape (and similarly keydouble and space2ctrl), however there is no program that perfectly deals with with using "normal" keys as modifiers. The closest is AHM which at least tries to do something about accidental presses, but I had to stop using it because it doesn't work perfectly. If anyone knows of another solution while I try to get tmk firmware running, I'd be happy to hear it.

My conclusion is not that character keys shouldn't be made into dual role keys; I think they are the best candidates. I think a hybrid chording system has a lot of potential. With enough easily accessible thumb keys, I probably wouldn't use more than 1 or 2.. 4 max probably. In the past I've used qwerty d to access my nav/misc layer (things like backspace, arrows, a few symbols, tmux prefix key, etc.) and spacebar for window management, launching most used programs, and my most important hotkeys. I wonder how well remapping shift to a letter on each side would work. As for modifiers as normal keys, I only ever do escape on release.

I have tried to implement SpaceFN in Linux using the record extension in X11.

Trouble is, it lets you intercept key presses, it lets you add keys to the event queue, but you cannot remove events from the queue!

So it works only for real modifiers. A modifier like Shift generates 2 events when you press then release it, and these events are ignored. When you detect the key release, you can then add an event to the queue (if no other key has been pressed in between). That's how xcape works.

It does not work for keys that generate a character, because you cannot remove this character from the event queue.

I don't know how to do better than that. Apparently if you want to be able to modify the event queue you will need to modify one of the Linux kernel drivers.

There is an utility called AutoKey that does key remapping, but it is buggy (it often crashes when you keep a key pressed) and apparently it works by dealing with the window manager, so it's not very portable and this approach suffers from other shortcomings.                       

Offline Pro XKB

  • Posts: 25
Re: Dual-role keys
« Reply #49 on: Tue, 11 February 2014, 12:59:37 »
> Trouble is, it lets you intercept key presses, it lets you add keys to the event queue, but you cannot remove events from the queue!

How about using ActionMessage:

http://geekhack.org/index.php?action=post;topic=41685.30;last_msg=1223995

Offline angelic_sedition

  • Posts: 124
  • Location: Flatland
Re: Dual-role keys
« Reply #50 on: Tue, 11 February 2014, 13:01:36 »


I have tried to implement SpaceFN in Linux using the record extension in X11.

Trouble is, it lets you intercept key presses, it lets you add keys to the event queue, but you cannot remove events from the queue!

So it works only for real modifiers. A modifier like Shift generates 2 events when you press then release it, and these events are ignored. When you detect the key release, you can then add an event to the queue (if no other key has been pressed in between). That's how xcape works.

It does not work for keys that generate a character, because you cannot remove this character from the event queue.

I don't know how to do better than that. Apparently if you want to be able to modify the event queue you will need to modify one of the Linux kernel drivers.

There is an utility called AutoKey that does key remapping, but it is buggy (it often crashes when you keep a key pressed) and apparently it works by dealing with the window manager, so it's not very portable and this approach suffers from other shortcomings.                     

I'm trying to implement it with python and xlib, but I'm not totally sure what I'm doing.

Autokey is more for text expansion. I haven't had any problems with it crashing, but it doesn't seem like a very good way to do it (as oppoed to a python script by itself and not bound to a key), and to the best of my knowledge, the devs aren't interested in implementing this sort of feature: https://code.google.com/p/autokey/issues/detail?id=200
QWERTY(104wpm) -> CarpalxQ(modded) -> Colemak(118wpm) -> Colemak-DH
Mouse less.

Offline Pro XKB

  • Posts: 25
Re: Dual-role keys
« Reply #51 on: Wed, 12 February 2014, 06:39:13 »
Sorry for sending the wrong link for ActionMessage.  This is the one I meant:

http://lists.x.org/archives/xorg/2010-September/051098.html

Offline islisis

  • Posts: 120
  • Location: Tokyo, Japan
Re: Dual-role keys
« Reply #52 on: Mon, 17 February 2014, 09:19:34 »
Various workloads have put Linux experimentation on the backburner :/ If you make any progress angelic I would help in any way possible (I had similar ideas about trying Autokey, I'm not sure how X input translates to future libraries like Wayland though).

Prototyping continues in AHK, on the LHS alone I've got 4 thumb keys and 3 pinky in varying DR capacities. Implementation in software is a necessity now due to interaction with mouse movement (as another DR trigger... erm and TR ^^;).

Semi-related: chorded the crap out of my 6 button mouse.
« Last Edit: Mon, 17 February 2014, 09:37:58 by islisis »

Offline shaaniqbal

  • Posts: 145
Re: Dual-role keys
« Reply #53 on: Mon, 17 February 2014, 15:09:52 »
If anyone's interested, my post here describes a method of using home row keys as triple-role keys:

http://geekhack.org/index.php?topic=52967.msg1178985#msg1178985

Offline angelic_sedition

  • Posts: 124
  • Location: Flatland
Re: Dual-role keys
« Reply #54 on: Tue, 18 February 2014, 21:00:08 »
Various workloads have put Linux experimentation on the backburner :/ If you make any progress angelic I would help in any way possible (I had similar ideas about trying Autokey, I'm not sure how X input translates to future libraries like Wayland though).

Prototyping continues in AHK, on the LHS alone I've got 4 thumb keys and 3 pinky in varying DR capacities. Implementation in software is a necessity now due to interaction with mouse movement (as another DR trigger... erm and TR ^^;).

Semi-related: chorded the crap out of my 6 button mouse.
I'm pretty busy as well myself. If X dies to Wayland, then I won't move anyway until I get the equivalent of things like xdotool, xdo, xmodmap, xsendkey, xchainkeys, etc. (without them I'm crippled). As for progress, I really have a lot of documentation to wade through before I find what I'm looking for. What would be great is if I could find some decent simple way to time the length of a keypress.

I was thinking a really simple way to do it would be to use sxhkd, which allows you to bind a key to a keypress or keyrelease. Sadly, it doesn't allow for you to have bindings for both. I was thinking it would be really easy to just start a timer on keypress and just keep looping and do nothing until keyrelease or until certain time length, after which it would act as a modifier until key release. The corresponding keyup binding would check the timer and send the normal key (i.e. space) if it was less than that time or do nothing if greater than the time. Alas, I don't think this will ever work, and it says something about my lack of progress that this is the best idea I've had so far.

I don't think the python xlib library hasn't been updated in years, so I'm not too confident about going down that road either.
« Last Edit: Tue, 18 February 2014, 21:02:15 by angelic_sedition »
QWERTY(104wpm) -> CarpalxQ(modded) -> Colemak(118wpm) -> Colemak-DH
Mouse less.

Offline islisis

  • Posts: 120
  • Location: Tokyo, Japan
Re: Dual-role keys
« Reply #55 on: Wed, 19 February 2014, 06:57:21 »
OK, I completely understand! It's an important long term project for me so I'm trying to think ahead, starting will likely be a miracle as I'll have lots to research. Keypress timers can work for simple decision logic and I use it for some DR keys (if it sends the modkey by default you don't need a loop just subtract the system time of the two events), but I want to write a more complete framework as interactions with other keypresses have become quite important.

As an aside, if you don't like AutoKey because it is limited to WMs this may not be better but there is also AutoPy (http://www.autopy.org) though doesn't seem to be maintained

Best of luck and keep us posted :)
« Last Edit: Wed, 19 February 2014, 07:25:50 by islisis »

Offline spiceBar

  • Posts: 998
    • ChessTiger.com
Re: Dual-role keys
« Reply #56 on: Wed, 19 February 2014, 06:58:18 »
Various workloads have put Linux experimentation on the backburner :/ If you make any progress angelic I would help in any way possible (I had similar ideas about trying Autokey, I'm not sure how X input translates to future libraries like Wayland though).

Prototyping continues in AHK, on the LHS alone I've got 4 thumb keys and 3 pinky in varying DR capacities. Implementation in software is a necessity now due to interaction with mouse movement (as another DR trigger... erm and TR ^^;).

Semi-related: chorded the crap out of my 6 button mouse.
I'm pretty busy as well myself. If X dies to Wayland, then I won't move anyway until I get the equivalent of things like xdotool, xdo, xmodmap, xsendkey, xchainkeys, etc. (without them I'm crippled). As for progress, I really have a lot of documentation to wade through before I find what I'm looking for. What would be great is if I could find some decent simple way to time the length of a keypress.

I was thinking a really simple way to do it would be to use sxhkd, which allows you to bind a key to a keypress or keyrelease. Sadly, it doesn't allow for you to have bindings for both. I was thinking it would be really easy to just start a timer on keypress and just keep looping and do nothing until keyrelease or until certain time length, after which it would act as a modifier until key release. The corresponding keyup binding would check the timer and send the normal key (i.e. space) if it was less than that time or do nothing if greater than the time. Alas, I don't think this will ever work, and it says something about my lack of progress that this is the best idea I've had so far.

I don't think the python xlib library hasn't been updated in years, so I'm not too confident about going down that road either.

I think the problem is not to receive events and time them. That's easy to do with the XRecord extension.

The problem is to modify the X event queue. You can add events but not remove events.

At least that's what has stopped me.

Offline angelic_sedition

  • Posts: 124
  • Location: Flatland
Re: Dual-role keys
« Reply #57 on: Wed, 19 February 2014, 11:49:23 »
I think the problem is not to receive events and time them. That's easy to do with the XRecord extension.

The problem is to modify the X event queue. You can add events but not remove events.

At least that's what has stopped me.
Ah well I haven't tried anything with xrecord extension. I've had no problem capturing and sending keystrokes with the methods I've tried, but so far they've all worked badly with timing.

OK, I completely understand! It's an important long term project for me so I'm trying to think ahead, starting will likely be a miracle as I'll have lots to research. Keypress timers can work for simple decision logic and I use it for some DR keys (if it sends the modkey by default you don't need a loop just subtract the system time of the two events), but I want to write a more complete framework as interactions with other keypresses have become quite important.

As an aside, if you don't like AutoKey because it is limited to WMs this may not be better but there is also AutoPy (http://www.autopy.org) though doesn't seem to be maintained

Best of luck and keep us posted :)
RIght now, I'm just trying to come up with something simple (and likely undesirably hackish..) that at least is usable. Something simple shouldn't be too hard to do.. as for something more complete.. python might not be the way to go.

As for autokey, I just don't really see the benefit, since you would just use python scripting with it anyway. It seems more of a hinderance. I'm confused about what you mean by limited to WMs though (I've never had it not work on any WMs or DEs) unless you're not talking about window managers? Unless autokey allows easy distinguishing between keydown and up (which it doesn't to the best of my knowledge), I don't really see it as helpful. Thing like xpybind and autopy (as you mentioned) are what I'm looking at right now for a simple solution. Though xpybind looks basically like a more capable xchainkeys.. I'm not sure it would actually be anymore useful to me than what I've already tried.

I'll update if I get anywhere.
« Last Edit: Wed, 19 February 2014, 11:52:45 by angelic_sedition »
QWERTY(104wpm) -> CarpalxQ(modded) -> Colemak(118wpm) -> Colemak-DH
Mouse less.

Offline islisis

  • Posts: 120
  • Location: Tokyo, Japan
Re: Dual-role keys
« Reply #58 on: Wed, 19 February 2014, 21:51:28 »
Sorry for the imprecise language, I mean on a gui level but I'm just not familiar with the details. I also naively assumed there was a key detection parity with key_press/key_release without doing any research. There is the function wait_for_keypress which I assume was introduced in response to this request, but I agree that the implementation is not complete enough to be a good candidate currently. I will see if we can rally up support for key press/release binding.

For me it seemed easier to implement it on top of a pre-existing remapping framework to avoid conflicts and allow better integration with system events, but I haven't don't any proper research.

Offline hoggy

  • * Ergonomics Moderator
  • Posts: 1502
  • Location: Isle of Man
Re: Dual-role keys
« Reply #59 on: Thu, 20 February 2014, 11:45:32 »
It's only just occurred to me that most of us have already encountered dual use keys - the windows key.  Pressing the win key by itself will bring up the start menu, but win-e will open explorer.  The start menu only appears when the win key is released, if no other button was pressed while the win key was down.  It's not a great discovery, I thought it might be a good example to bring up.                                       
GH Ergonomic Guide (in progress)
http://geekhack.org/index.php?topic=54680.0

Offline islisis

  • Posts: 120
  • Location: Tokyo, Japan
Re: Dual-role keys
« Reply #60 on: Fri, 21 February 2014, 23:43:31 »
Good example, it seems to me alt can considered DR in the same way (and a good candidate for customising for that same reason), as are some change language shortcuts such as alt-shift. It will be interesting to see what are keys can be seen as safe enough for consumption :)
« Last Edit: Sun, 23 February 2014, 00:05:55 by islisis »

Offline Chendy

  • Posts: 3
Re: Dual-role keys
« Reply #61 on: Wed, 05 October 2016, 08:16:31 »
Does anybody know a working script for Windows? i just want space and shift. i was using the script below but doesnt work on my windows 8.1 anymore, no idea why

https://github.com/yutaszk/win-sands-ahk

i posted a question to Stack Exchange, but no luck so far

http://superuser.com/questions/1122228/windows-sands-space-and-shift-aka-dual-role-key-spacebar-works-as-spaceba

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Dual-role keys
« Reply #62 on: Wed, 05 October 2016, 18:48:58 »
Couldn't  you fix the script?
It seems like very simple clean and easy to hack, what's actually your problem?

Offline wilderjds

  • Posts: 3
Re: Dual-role keys
« Reply #63 on: Thu, 17 November 2016, 20:10:33 »
Just my 2 cents on the rollover detection criterion.  I am interested in using the spacebar as an extra ctrl, so there is a lot of problems with fast typing rollover.

 I found that adding timeouts makes things a bit unpredictable, so I don't like them as a solution. What I ended up doing, and it works quite well even in actual real world typing,  at least for me, is the following.

If spacebar is pressed, X is released,  then treat the spacebar press as a space press.

If spacebar is pressed,  X is pressed and spacebar is released,  treat the spacebar events as space events

Otherwise treat the spacebar press (and the following release) as a ctrl.

I guess the key thing is the first of the checks. It makes all the difference in the world for me.
I am implementing it with a patched version of the ahm patched evdev driver.

Offline angelic_sedition

  • Posts: 124
  • Location: Flatland
Re: Dual-role keys
« Reply #64 on: Tue, 06 December 2016, 16:47:05 »
Just my 2 cents on the rollover detection criterion.  I am interested in using the spacebar as an extra ctrl, so there is a lot of problems with fast typing rollover.

 I found that adding timeouts makes things a bit unpredictable, so I don't like them as a solution. What I ended up doing, and it works quite well even in actual real world typing,  at least for me, is the following.

If spacebar is pressed, X is released,  then treat the spacebar press as a space press.

If spacebar is pressed,  X is pressed and spacebar is released,  treat the spacebar events as space events

Otherwise treat the spacebar press (and the following release) as a ctrl.

I guess the key thing is the first of the checks. It makes all the difference in the world for me.
I am implementing it with a patched version of the ahm patched evdev driver.

Could you elaborate on why you don't like timeouts? To me it seems the best way to implement dual-role would be with a customizable delay before the key starts acting as a modifier combined with a customizable minimal overlap time. Also, the decision should be made on key release (not press) or when the delay time is reached.

For the first case you describe, is X pressed before space? I'm not sure I like the idea of depending on release order as much. I thought ahm already did this, but I guess I was wrong. Do you have your version available somewhere, so I could try it?

As a side note, I encountered someone who uses space as control with xcape. This person was able to get used to it and change how they type to work around the problem (no rolling with space bar). Ideally I'd like to have dual-roled home row keys, so this approach isn't feasible for me, but I found it interesting nonetheless.
QWERTY(104wpm) -> CarpalxQ(modded) -> Colemak(118wpm) -> Colemak-DH
Mouse less.

Offline angelic_sedition

  • Posts: 124
  • Location: Flatland
Re: Dual-role keys
« Reply #65 on: Thu, 08 December 2016, 00:14:58 »
Related to my posts from years ago, I never got anywhere mostly due to lack of time, experience, documentation, and simple examples of what I wanted to do in python. As far as I understand X (and I don't understand it all that well), you can only grab/capture all keys if you have a mapped window (and only when that window is active; this is how normal programs work). As for globally capturing keys, only one program can globally capture a specific key combination (this is how hotkey daemons work). This seems to leave only a few possibilities for creating an "intelligent" dual-role program:

1. Capture the modifier in question plus all letter keys
- Potential for conflict with keys bound by a hotkey daemon or window manager (potentially impossible or inconvenient to dual-role for certain modifiers)

2. Capture all unmodified letter/number/etc. keys
- Since all typing (without modifiers) is going through the dual-role program, reliability is a potential issue

3. Grab just the dual-role keys, and activate a window that will capture all input when they are pressed
+ When a dual-role key is not in use, input is not going through the dual-role program
+ Probably easier to implement modifier combinations like this (no possibility for conflict so can capture all modifier combinations)
- Requires a visible window (not neccessarily the worst thing if you consider that programs like plover and ibus have windows); maybe could make it really small (I'm pretty sure it still has to be mapped though)
- Requires focus switching

I recently became interested in working on this again. Yesterday I attempted to get the second method working using an X library in a different language with more extensive documentation. I now have something that allows for optionally enforcing a minimum delay time, a minimum overlap time, and release order (non-dual-role must be released first). I've never tested a dual-role program with configurable options like these before, so these are my initial observations:

1. Having a short delay alone seems to be a pretty good way of preventing incorrect results without adjusting typing (error: either the user accidentally uses the key as a modifier or they want to use it as a modifier but didn't hold it down long enough). I think this may be a viable method for using home row keys as dual-role keys.

2. I'm not sure if the difference between the key overlap time is significant enough for a minimum overlap time to be much good. It would have to be shorter than the average time a key is held when typing but longer than the overlap between two keys when typing. These two times are pretty close, so I need to test this more. If they vary enough to overlap a lot of the time, this won't be very useful.

3. Checking release order can prevent most errors as well. The potential downside is that you may have to retrain yourself to always release modifier keys last (though this isn't a huge deal). A combination of this and a delay may be very reliable.

4. While I think some combinations of these methods could give pretty good results, I'm not sure how good an using X for the implementation is. Right now, I'm encountering a problem where not all key release events are reported (not sure if this is a bug in the library or a problem with how I'm using it). I don't know if anyone is still interested, but if I can workaround this problem (given when it happens, it may not even be necessary to fix it), I can put the program up for others to test. At this stage, it seems somewhat promising, but it may turn out that it's not a viable solution. Maybe improving AHM is the way to go. I may also want to look at software like ibus to see input is captured. There is one clear benefit to this approach though. It makes it easily possible to create an extra layer for a dual-role key instead of binding it to a specific modifier. This layer could consist of both normal keypresses as well as custom shell commands. I could also easily include a piece of software that would have you type normally and then help you choose minimum delay/overlap times.
QWERTY(104wpm) -> CarpalxQ(modded) -> Colemak(118wpm) -> Colemak-DH
Mouse less.

Offline Pro XKB

  • Posts: 25
Re: Dual-role keys
« Reply #66 on: Thu, 08 December 2016, 13:23:35 »
Quote
This seems to leave only a few possibilities for creating an "intelligent" dual-role program:
Grabbing is not your only option.  You could use the RECORD extension, the ActionMessage approach I mentioned above.

Offline islisis

  • Posts: 120
  • Location: Tokyo, Japan
Re: Dual-role keys
« Reply #67 on: Fri, 09 December 2016, 07:57:02 »
my dev environment has been in limbo for almost a year, but i'm committed to long term work on this.

just a couple naive questions:

1. Is this method implementable through libinput?

2. Can you make calls to the extra layers through python easily? It would indeed be nice to have a basic framework for defining potentially unlimited mod keys, etc.

Offline angelic_sedition

  • Posts: 124
  • Location: Flatland
Re: Dual-role keys
« Reply #68 on: Wed, 14 December 2016, 16:32:21 »
Grabbing is not your only option.  You could use the RECORD extension, the ActionMessage approach I mentioned above.

Well I meant from an xlib/xcb standpoint; there is also AHM of course, which modifies evdev. As for XKB, I've never liked it, and the method described there seems a lot more complicated for both the implementor and the user. I personally wouldn't easily be able to implement dual-role that way.

1. Is this method implementable through libinput?

I know very little about libinput. My guess is that it's probably possible, but I don't now if this would be the best solution. From my understanding, this may require maintaining an alternate version of libinput (I may be wrong). I'll mess around with libinput some when I have the time. The implementation method would be very similar but possibly easier/more powerful (since like with AHM, all keys would pass through it).

2. Can you make calls to the extra layers through python easily? It would indeed be nice to have a basic framework for defining potentially unlimited mod keys, etc.

I abandoned using python with its xlib library because I couldn't understand it easily/quickly. I'm not entirely sure what you're asking, but it's easily possible to create a fake modifier with this method. It's kind of comparable to binding key combinations to "xdotool key ..." with a hotkey daemon but more direct.

Edit: I don't think it's actually possible to bind a non modifier + non modifier combination with any hotkey daemons, so it's not a very good analogy.
« Last Edit: Wed, 14 December 2016, 16:59:02 by angelic_sedition »
QWERTY(104wpm) -> CarpalxQ(modded) -> Colemak(118wpm) -> Colemak-DH
Mouse less.

Offline T42

  • Posts: 16
  • Location: Germany
another Autohotkey implementation attempt
« Reply #69 on: Mon, 22 October 2018, 12:11:57 »
I have tried to implement dual-role keys which do not require any timing tradeoffs in Autohotkey.

Unfortunately, although the automated tests suggest otherwise, it does not work in practice: Often, modifiers or layers get locked (i.e. key up events seem to be missing). At that point, I gave up for the time being. (I noticed that you can have actually fit 15 dedicated modifier keys on a standard keyboard. :-)

Since I currently have no plans to continue working on it, I share it as a forum post instead of a proper repository.

Offline kbder

  • Posts: 6
Re: Dual-role keys
« Reply #70 on: Thu, 20 December 2018, 18:30:12 »
Looks like I'm the next in line to pick up this torch and try to carry it forward!  :eek:

I'm just getting my head wrapped around QMK, but it seems that the critical thing for dual-role keys is that they can only be properly disambiguated upon the next key UP event (and that key up's corresponding key down must have started at or after the dual-role key).

for example, if key0 is dual-role as SHIFT and 'a', and key1 is just a normal 'b' key, here are some sequences and how they should be interpreted:

key0 down, key0 up -> a down, a up

key0 down, key1 down, key0 up, key1 up -> a down, b down, a up, b up

key0 down, key1 down, key1 up, key0 up -> SHIFT down, b down, b up, SHIFT up

because we have process_record_user(), I think we can pull this off, because we can completely override what QMK does with keystrokes.  We just need to buffer ambiguous keys until the next up stroke disambiguates them.

For a user with 10 fingers, the most we should need to buffer before we can start disambiguating is 10 downstrokes and 1 upstroke.  That shouldn't be a problem as far as RAM consumption.  I've gotten started throwing together a little ring buffer to accomplish this.

I'll post more as I actually get something closer to working.

Offline kbder

  • Posts: 6
Re: Dual-role keys
« Reply #71 on: Thu, 20 December 2018, 18:37:11 »

Offline kbder

  • Posts: 6
Re: Dual-role keys
« Reply #72 on: Sat, 22 December 2018, 00:51:13 »
Ok, I have an initial implementation working!  https://github.com/qmk/qmk_firmware/pull/4709

Currently it only handles dual-role modifiers.  Next I'd like to have similar dual-role momentary layer switching, and finally a "layer hold" key which will allow for switching a layer and then using the dual-role modifiers from within that layer.

Offline kbder

  • Posts: 6
Re: Dual-role keys
« Reply #73 on: Sat, 22 December 2018, 01:17:30 »
(including gifs from the github pull request for illustration, see https://github.com/qmk/qmk_firmware/pull/4709 for details)