1

I know how to set up keybindings where you have to hold down one of the keys of type KeyMask. Which are: Alts, Ctrls, Windowskeys. Also, giving 0 as the KeyMask can be used to define single-key commands.

But I cannot assign arbitrary keys as KeyMask. Most keys are of type KeySym and with explicit conversions it does not work.

How can you assign arbitrary key combos? Or is that only possible with far too much hacking?

for example F1+F2

  • Probably not: the way X works underneath, applications can easily recognize events of the form set_of_modifiers+non-modifier-key. Recognizing combinations of non-modifiers requires a lot more coding. – Gilles 'SO- stop being evil' May 5 '15 at 23:37
1

You can't do it directly as modifier keys are different from the other keys. All KeyPress or KeyRelease events contain a field indicating the state of the modifier keys, so when you get a "A key pressed" event, you know if it is just A or Ctrl+A. But for other keys, you have to keep track yourself of whether they have been pressed before your second key.

The module XMonad.Actions.Submap provides a submap action to add to your key bindings that will grab the keyboard and wait for the next key press event then return the matching action from the map. So for F1 then F2 you can add to your list of key bindings :

myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
    [

     ((0, xK_F1),  submap . M.fromList $
                         [ 
                          ((0, xK_F2),  someAction)
                         ])
    ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.