5

I am trying to map keys in KWin like Meta + KP4 in Kubuntu 11.04.

If numlock is on, it gets recorded as "Meta + 4" and then works with the 4 on the main keyboard, but NOT on the keypad.

If numlock is off, it gets recorded as "Meta + Left" and then works with the left arrow on the main keyboard, but NOT on the keypad.

I want it to work on the keypad! Maybe there is some option in the keyboard settings...?

evencoil
  • 777

5 Answers5

8

Thanks for the lead, there was a suggestion of a workaround in it. Here it is in case anyone else runs into this:

Create ~/.Xmodmap with the following text:

keycode 87 = XF86Launch1
keycode 88 = XF86Launch2
keycode 89 = XF86Launch3
keycode 83 = XF86Launch4
keycode 84 = XF86Launch5
keycode 85 = XF86Launch6
keycode 79 = XF86Launch7
keycode 80 = XF86Launch8
keycode 81 = XF86Launch9
keycode 90 = XF86LaunchA
keycode 91 = XF86LaunchB

I also added

keycode 86 = XF86LaunchC
keycode 82 = XF86LaunchD

which is for keypad +/-.

Then run xmodmap ~/.Xmodmap. You should be able to bind the to the keys now. Also, if other keys aren't working try the utility xev, which can tell you what the keycode is for a specific key and add it in a similar way.

Vince
  • 324
evencoil
  • 777
  • This works, and I added it to run automatically on startup. Btw, I want to say neither the numbers of the numpad nor the key arrows (Bloq Num on/off) don't work at all. – Unix Aug 19 '15 at 19:12
1

using xmodmap works but means the numpad can't be used as an actual numpad. The following workaround allows the numpad to be used to tile windows but also as a numpad.

Install xbindkeys

sudo apt-get install xbindkeys

Setup hotkeys

Add the following to ~/.xbindkeysrc. You may need to modify the key combination depending on your setup and desired hotkeys. This script uses the windows key and numpad. Running xbindkeys -k will allow you to discover what codes map to keys when you push them.

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Bottom Left'"
Mod4 + Super_L + KP_1

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Bottom'"
Mod4 + Super_L + KP_2

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Bottom Right'"
Mod4 + Super_L + KP_3

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Left'"
Mod4 + Super_L + KP_4

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Maximize'"
Mod4 + Super_L + KP_5

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Right'"
Mod4 + Super_L + KP_6

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Top Left'"
Mod4 + Super_L + KP_7

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Top'"
Mod4 + Super_L + KP_8

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Top Right'"
Mod4 + Super_L + KP_9
1

Maybe this is related - A bug report: Bug 183458 - Numpad (keypad) keys not mapped correctly when setting Global Shortcuts / https://bugs.kde.org/show_bug.cgi?id=183458

user26687
  • 14,934
0

To improve on evencoil's answer you can change the binding of the numpad keys while preserving the normal behaviour when Num Lock is ON by using this ~/.Xmodmap instead:

! this xmodmap file changes the Num Lock OFF binds of all Keypad keys to make it easier to make custom shortcuts with these keys using XF86Launch codes
! what are XF86Launch symbolic codes: https://askubuntu.com/a/1064810/1560675
! note that by using these you lose the default Num Lock OFF binds  (duh?) I left them here commented out just for reference
! from: https://askubuntu.com/a/1463491/1560675
! you can use the "xev" command to make sure the keys are the same for your keyboard
! you might need to use other XF86Launch codes like XF86LaunchD XF86LaunchE and XF86LaunchF if some of the ones used here are already used by other hardware keys already (some keyboards have dedicated hardware buttons for these codes but they are quite rare) or another custom xmodmap you might be using
! you can comment the lines that change binding you do not need simply by adding a "!" in the beginning of the corrisponding line (lines starting with "!" are comment and will be ignored by xmodmap)
! I have left the original bindings commented out just as reference

! default key 79 uses "Keypad Home" with Num Lock OFF and "Keypad 7" with Num Lock ON !keycode 79 = KP_Home KP_7 KP_Home KP_7 ! custom key 79 uses "XF86Launch0" with Num Lock OFF and "Keypad 7" with Num Lock ON keycode 79 = XF86Launch0 KP_7 XF86Launch0 KP_7

! default key 80 uses "Keypad Up" with Num Lock OFF and "Keypad 8" with Num Lock ON !keycode 80 = KP_Up KP_8 KP_Up KP_8 ! custom key 80 uses "XF86Launch1" with Num Lock OFF and "Keypad 8" with Num Lock ON keycode 80 = XF86Launch1 KP_8 XF86Launch1 KP_8

! default key 81 uses "Keypad Prior" with Num Lock OFF and "Keypad 9" with Num Lock ON !keycode 81 = KP_Prior KP_9 KP_Prior KP_9 ! custom key 81 uses "XF86Launch2" with Num Lock OFF and "Keypad 9" with Num Lock ON keycode 81 = XF86Launch2 KP_9 XF86Launch2 KP_9

! default key 82 uses "Keypad Subtract" with Num Lock OFF and "Keypad Subtract" with Num Lock ON !keycode 82 = KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract XF86Prev_VMode ! custom key 82 uses "XF86Launch3" with Num Lock OFF and "Keypad Subtract" with Num Lock ON keycode 82 = XF86Launch3 KP_Subtract XF86Launch3 KP_Subtract KP_Subtract KP_Subtract XF86Prev_VMode

! default key 83 uses "Keypad Left" with Num Lock OFF and "Keypad 4" with Num Lock ON !keycode 83 = KP_Left KP_4 KP_Left KP_4 ! custom key 83 uses "XF86Launch4" with Num Lock OFF and "Keypad 4" with Num Lock ON keycode 83 = XF86Launch4 KP_4 XF86Launch4 KP_4

! default key 84 uses "Keypad Begin" with Num Lock OFF and "Keypad 5" with Num Lock ON !keycode 84 = KP_Begin KP_5 KP_Begin KP_5 ! custom key 84 uses "XF86Launch5" with Num Lock OFF and "Keypad 5" with Num Lock ON keycode 84 = XF86Launch5 KP_5 XF86Launch5 KP_5

! default key 85 uses "Keypad Right" with Num Lock OFF and "Keypad 6" with Num Lock ON !keycode 85 = KP_Right KP_6 KP_Right KP_6 ! custom key 85 uses "XF86Launch6" with Num Lock OFF and "Keypad 6" with Num Lock ON keycode 85 = XF86Launch6 KP_6 XF86Launch6 KP_6

! default key 86 uses "Keypad Add" with Num Lock OFF and "Keypad 6" with Num Lock ON !keycode 86 = KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add XF86Next_VMode ! custom key 86 uses "XF86Launch7" with Num Lock OFF and "Keypad 6" with Num Lock ON keycode 86 = XF86Launch7 KP_Add XF86Launch7 KP_Add KP_Add KP_Add XF86Next_VMode

! default key 87 uses "Keypad End" with Num Lock OFF and "Keypad 1" with Num Lock ON !keycode 87 = KP_End KP_1 KP_End KP_1 ! custom key 87 uses "XF86Launch8" with Num Lock OFF and "Keypad 1" with Num Lock ON keycode 87 = XF86Launch8 KP_1 XF86Launch8 KP_1

! default key 88 uses "Keypad Down" with Num Lock OFF and "Keypad 2" with Num Lock ON !keycode 88 = KP_Down KP_2 KP_Down KP_2 ! custom key 88 uses "XF86Launch9" with Num Lock OFF and "Keypad 2" with Num Lock ON keycode 88 = XF86Launch9 KP_2 XF86Launch9 KP_2

! default key 89 uses "Keypad Next" with Num Lock OFF and "Keypad 3" with Num Lock ON !keycode 89 = KP_Next KP_3 KP_Next KP_3 ! default key 89 uses "XF86LaunchA" with Num Lock OFF and "Keypad 3" with Num Lock ON keycode 89 = XF86LaunchA KP_3 XF86LaunchA KP_3

! default key 90 uses "Keypad Insert" with Num Lock OFF and "Keypad 0" with Num Lock ON !keycode 90 = KP_Insert KP_0 KP_Insert KP_0 ! default key 90 uses "XF86LaunchB" with Num Lock OFF and "Keypad 0" with Num Lock ON keycode 90 = XF86LaunchB KP_0 XF86LaunchB KP_0

! default key 91 uses "Keypad Delete" with Num Lock OFF and "Keypad Decimal" with Num Lock ON !keycode 91 = KP_Delete KP_Decimal KP_Delete KP_Decimal ! default key 91 uses "XF86LaunchC" with Num Lock OFF and "Keypad Decimal" with Num Lock ON keycode 91 = XF86LaunchC KP_Decimal XF86LaunchC KP_Decimal

To do that you can use any editor like nano, run: nano ~/.Xmodmap and paste the above content inside it, then Ctrl+s and Ctrl+x to save and exit, then reboot or restart the x session. If after rebooting or restarting the x session it does not work you might need to check this out: https://askubuntu.com/a/1463479/1560675

0

Bryce Drennan's solution is very nice, although I wanted to have a slightly different keybinding. To emulate Ubuntu/Unity settings, use the following in ~/.xbindkeysrc:

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Bottom Left'"
Control + Mod2 + Mod4 + Super_L + KP_End

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Bottom'"
Control + Mod2 + Mod4 + Super_L + KP_Down

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Bottom Right'"
Control + Mod2 + Mod4 + Super_L + KP_Next

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Left'"
Control + Mod2 + Mod4 + Super_L + KP_Left

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Maximize'"
Control + Mod2 + Mod4 + Super_L + KP_Begin

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Right'"
Control + Mod2 + Mod4 + Super_L + KP_Right

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Top Left'"
Control + Mod2 + Mod4 + Super_L + KP_Home

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Top'"
Control + Mod2 + Mod4 + Super_L + KP_Up

"qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Window Quick Tile Top Right'"
Control + Mod2 + Mod4 + Super_L + KP_Prior
Martijn
  • 132