File: keysyms.c

package info (click to toggle)
linux 6.16.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,724,576 kB
  • sloc: ansic: 26,558,545; asm: 271,315; sh: 143,998; python: 72,469; makefile: 57,126; perl: 36,821; xml: 19,553; cpp: 5,820; yacc: 4,915; lex: 2,955; awk: 1,667; sed: 28; ruby: 25
file content (44 lines) | stat: -rw-r--r-- 1,194 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* SPDX-License-Identifier: GPL-2.0 */

#include "keysyms.h"
#include <linux/ctype.h>
#include <linux/kernel.h>

const char *key_name(int key, char *bf, size_t size)
{
	if (isprint(key)) {
		scnprintf(bf, size, "%c", key); 
	} else if (key < 32) {
		scnprintf(bf, size, "Ctrl+%c", key + '@'); 
	} else {
		const char *name = NULL;

		switch (key) {
		case K_DOWN:	name = "Down";	    break;
		case K_END:	name = "End";	    break;
		case K_ENTER:	name = "Enter";	    break;
		case K_ESC:	name = "ESC";	    break;
		case K_F1:	name = "F1";	    break;
		case K_HOME:	name = "Home";	    break;
		case K_LEFT:	name = "Left";	    break;
		case K_PGDN:	name = "PgDown";    break;
		case K_PGUP:	name = "PgUp";	    break;
		case K_RIGHT:	name = "Right";	    break;
		case K_TAB:	name = "Tab";	    break;
		case K_UNTAB:	name = "Untab";	    break;
		case K_UP:	name = "Up";	    break;
		case K_BKSPC:	name = "Backspace"; break;
		case K_DEL:	name = "Del";	    break;
		default:
			if (key >= SL_KEY_F(1) && key <= SL_KEY_F(63))
				scnprintf(bf, size, "F%d", key - SL_KEY_F(0));
			else
				scnprintf(bf, size, "Unknown (%d)", key);
		}

		if (name)
			scnprintf(bf, size, "%s", name);
	}

	return bf;
}