Bug 226553 - kbdcontrol doesn't map function keys
Summary: kbdcontrol doesn't map function keys
Status: Closed Feedback Timeout
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-03-12 13:21 UTC by Sergey
Modified: 2021-01-24 15:19 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey 2018-03-12 13:21:44 UTC
Hello.
At the moment I'm not able to map keys using kbdcontrol on VT console. When I for example enter:
# kbdcontrol -f 1 'ls'
The command is not assigned to F1 function key. Can you have a look at this?

Regards,
Sergey.
Comment 1 Arshan Khanifar 2018-03-27 20:56:15 UTC
I'm taking a look at this. Seems to be a problem in CURRENT as well.
Comment 2 Sergey 2018-03-28 14:26:28 UTC
(In reply to Arshan Khanifar from comment #1)
Hello Arshan,
There are patches suggested for several files in this thread:
https://forums.freebsd.org/threads/kbdmap-and-keyboard-mapping-files.57444/post-328546

I tried to edit keymap file and added escape controls to usr.sbin/kbdcontrol/kbdcontrol.c, but looks that is not enough. Additional files needs to be patched also.

Can you take a look at the thread and possibly add those fixes to upstream?

Best regards,
Sergey.
Comment 3 Arshan Khanifar 2018-03-28 17:02:22 UTC
(In reply to Sergey from comment #2)
Thanks for the thread! Yes I'll look into it.
Comment 4 Arshan Khanifar 2018-03-29 19:32:23 UTC
(In reply to Sergey from comment #2)
I don't really think the thread relates to this, however I've tried the same thing having set the system terminal to sc(4), and the function key doesn't work there either. 

My suspicion is that this probably is some problem with the keyboard driver. I believe it doesn't emit the proper scan-code. I'll investigate further.
Comment 5 Sergey 2018-03-29 19:42:23 UTC
(In reply to Arshan Khanifar from comment #4)
Regarding scan codes you can install kbdscan for that. The problem is that mapping is not working at all, for example I'm not able to map Alt/Ctrl/Shift + Arrow keys to be able to use micro editor on console.
Unfortunately xterm on console doesn't support 256 colors either :(
Comment 6 Arshan Khanifar 2018-04-02 18:31:20 UTC
(In reply to Sergey from comment #5)
It turns out that vt(4) was using teken's keystrings for the function keys, and while the function key strings were in fact getting set, it wasn't using them. 
I'm not sure if it was originally the intent for teken to override the keystrings. Manual page of kbdcontrol(1) doesn't seem to suggest so. 

Anyways, I've made this patch: D14936 which makes vt(4) to use the function key strings if they have been set. The behavior is same as before if the keys have not been set.
Comment 7 Arshan Khanifar 2018-04-02 18:32:45 UTC
Err, this is the patch review D14936
Comment 8 Sergey 2018-04-03 08:18:47 UTC
(In reply to Arshan Khanifar from comment #7)
Hello Arshan,
Will the patch be merged with 11 current?
BR,
Sergey.
Comment 9 Sergey 2018-04-03 08:59:44 UTC
And another question,
function keys are limited to 65 or I can use up to 108?
Because I'd like to map for example CtrlShiftUp to fkey66 in kbd file and then
kbdcontrol -f 66 '\033[1;6A'
Comment 10 Sergey 2018-04-06 17:34:14 UTC
If I'm not mistaken after patching arrow keys and PgUp, PgDn do not work in less anymore.
Comment 11 Sergey 2019-02-01 08:08:24 UTC
Hello Arshan,
In FreeBSD 12-RELEASE, I'm still not able to assign commands using kbdcontrol. Hasn't the patch been merged? How can we solve the issue?
Best regards,
Sergey.
Comment 12 commit-hook freebsd_committer freebsd_triage 2019-02-01 16:08:49 UTC
A commit references this bug:

Author: bde
Date: Fri Feb  1 16:07:49 UTC 2019
New revision: 343663
URL: https://svnweb.freebsd.org/changeset/base/343663

Log:
  Fix function keys for syscons in cons25 mode (vidcontrol -T cons25).

  kbd(4) (but only documented in atkbd(4)) maintains a table of strings
  for 96 function keys.  Using teken broke this 9+ years ago for the
  most usable first 12 function keys and for 10 cursor keys, by supplying
  its own non-programmable strings so that the keyboard driver's strings
  are not used.

  Fix this by supplying NULL in the teken layer for syscons in cons25 mode
  so that the the strings are found in the kbd(4) layer.

  vt needs more changes to use kbd(4)'s tables.  Teken's cons25 table is
  still needed to supply nonempty strings for vt in cons25 mode.

  Keep using teken's xterm tables for both syscons and vt in xterm mode.
  Function keys should at least default to xterm values in xterm mode,
  and kbd(4) doesn't support this.

  teken_set_cons25() sets a sticky flag to ask for the fix, and space is
  reserved for another new flag.  vt should set this flag when it uses
  kbd(4)'s tables.

  PR:		226553 (for vt)

Changes:
  head/sys/teken/teken.c
Comment 13 Sergey 2019-02-20 06:56:58 UTC
(In reply to commit-hook from comment #12)
Hello,
Patching teken.c file alone as well as together with https://reviews.freebsd.org/D14936 doesn't solve the issue for me( I'm still not able to assign strings to keys... Am I doing something wrong?
BR,
Sergey.
Comment 14 Sergey 2019-10-03 16:38:50 UTC
This patch https://reviews.freebsd.org/D14936 actually does work, but I have several concerns. 
In order to be able to map fkeys to for example Ctrl/Alt/Shift + ArrowKeys
line
if (fkey >=0 && fkey < 65) {
have to chenged to 
if (fkey >=0 && fkey < 97) {
And second problem is that after patching, some keys on the console misbehave, for example Del key starts to work as Backspace. Or in 'less' pager arrow keys and PgUp/PgDn doesn't work anymore. Rebuilding without the patch fixes the keys behaviour.
Best regards,
Sergey.
Comment 15 Sergey 2019-10-08 17:31:21 UTC
Changing line
if (fkey >=0 && fkey < 65) {
to
if (fkey > 64 && fkey < 97) {
solves the issue.
BR.