How to get numeric keypad arrows working with java applications on Linux

不问归期 提交于 2019-12-07 01:11:55

问题


The arrow keys on the numeric keypad do not work with Java applications on Linux. Strangely enough, the Home, End, PgUp, PgDn, Ins, Del all work.

This is especially annoying when using Intellij for programming.

How do you get the arrow keys working?


回答1:


IntelliJ (and CLion) provides the functionality to configure key mappings. Under File->Settings->Keymap->Editor actions it is possible to assign both of the keystrokes ("normal" up/down/left/right and the keypad ones) to corresponding actions. Once this is done, all works like a charm. No need to fiddle with xkb or something.




回答2:


Physical keys on a keyboard are mapped to key codes using xkb. Here's how I got numeric keys working with java applications (like Intellij) on a Debian derivative of Linux:

  1. Switch to root user
  2. cd /usr/share/X11/xkb/symbols
  3. cp keypad keypad.original (just in case)
  4. Edit keypad and replace all occurrences of KP_Up, KP_Down, KP_Left & KP_Right with Up, Down, Left & Right, respectively
  5. Save
  6. dpkg-reconfigure xkb-data
  7. Reboot

Now the numeric keypad will emit the regular, arrow, key codes and not the java-unrecognised, numeric keypad, arrow, key codes.




回答3:


I don't have enough reputation to comment, but Peter L's solution really fixed this problem for me after a very long struggle.

I created a bash script to automate it and thought I'd share it here:

#!/bin/bash

SYMBOLS="/usr/share/X11/xkb/symbols"
KEYPAD="$SYMBOLS/keypad"

# create a backup in a temporary directory
TMP=$(mktemp -d)
cp "$KEYPAD" "$TMP/keypad"

# make a numbered backup in the original directory
sudo cp --backup=numbered "$TMP/keypad" "$SYMBOLS"

# fix the keypad file into the temporary directory
KEYS=("Up" "Down" "Left" "Right" "Home" "End" "Prior" "Next")
REGEX="s/KP_\("${KEYS[0]}$(printf "\|%s" "${KEYS[@]:1}")"\)/\1/g"
sed -e "$REGEX" "$KEYPAD" > "$TMP/keypad"

# overwrite the original keypad file
sudo cp "$TMP/keypad" "$KEYPAD"

# delete the temporary directory
rm -rf "$TMP"

# update the xkb symbols
sudo dpkg-reconfigure xkb-data

EDIT: improved version




回答4:


Another option:

  1. edit /etc/default/keyboard (save a copy just in case)
  2. Add or Update the value for XKBOPTIONS to "numpad:microsoft"
  3. Save File
  4. reboot


来源:https://stackoverflow.com/questions/32753190/how-to-get-numeric-keypad-arrows-working-with-java-applications-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!