问题
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:
- Switch to root user
- cd /usr/share/X11/xkb/symbols
- cp keypad keypad.original (just in case)
- Edit keypad and replace all occurrences of KP_Up, KP_Down, KP_Left & KP_Right with Up, Down, Left & Right, respectively
- Save
- dpkg-reconfigure xkb-data
- 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:
- edit /etc/default/keyboard (save a copy just in case)
- Add or Update the value for XKBOPTIONS to "numpad:microsoft"
- Save File
- reboot
来源:https://stackoverflow.com/questions/32753190/how-to-get-numeric-keypad-arrows-working-with-java-applications-on-linux