-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeycodes.cpp
More file actions
43 lines (35 loc) · 1021 Bytes
/
keycodes.cpp
File metadata and controls
43 lines (35 loc) · 1021 Bytes
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
/*
* See license.txt
*/
#include <map>
#include <functional>
#include <ctype.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "linenoise.h"
int
main ()
{
char quit[4];
printf("Linenoise key codes debugging mode.\n"
"Press keys to see scan codes. Type 'quit' at any time to exit.\n");
if (lnEnableRawMode(STDIN_FILENO) == -1) return -1;
memset(quit,' ',4);
while(1) {
char c;
int nread;
nread = read(STDIN_FILENO,&c,1);
if (nread <= 0) continue;
memmove(quit, quit+1, sizeof(quit)-1); /* shift string to left. */
quit[sizeof(quit)-1] = c; /* Insert current char on the right. */
if (memcmp(quit,"quit",sizeof(quit)) == 0) break;
printf("'%c' %02x (%d) (type quit to exit)\n",
isprint(c) ? c : '?', (int)c, (int)c);
printf("\x1b[0G"); /* Go left edge manually, we are in raw mode. */
fflush(stdout);
}
lnDisableRawMode(STDIN_FILENO);
return 0;
}