Merge 1.x into master #2
|
@ -20,29 +20,34 @@ use RuntimeException;
|
|||
final class Getch
|
||||
{
|
||||
// Special key codes
|
||||
public const GETCH_SPECIAL = 0;
|
||||
public const GETCH_F1 = 59;
|
||||
public const GETCH_F2 = 60;
|
||||
public const GETCH_F3 = 61;
|
||||
public const GETCH_F4 = 62;
|
||||
public const GETCH_F5 = 63;
|
||||
public const GETCH_F6 = 64;
|
||||
public const GETCH_F7 = 65;
|
||||
public const GETCH_F8 = 66;
|
||||
public const GETCH_F9 = 67;
|
||||
public const GETCH_F10 = 68;
|
||||
public const GETCH_F11 = 87;
|
||||
public const GETCH_F12 = 88;
|
||||
public const GETCH_UP_ARROW = 72;
|
||||
public const GETCH_LEFT_ARROW = 75;
|
||||
public const GETCH_RIGHT_ARROW = 77;
|
||||
public const GETCH_DOWN_ARROW = 80;
|
||||
public const GETCH_DELETE = 83;
|
||||
public const GETCH_HOME = 102;
|
||||
public const GETCH_PGUP = 104;
|
||||
public const GETCH_END = 107;
|
||||
public const GETCH_PGDN = 109;
|
||||
public const GETCH_INSERT = 110;
|
||||
// Extended scan code used to indicate special keyboard functions
|
||||
public const KEY_RESERVED = 0;
|
||||
public const KEY_E0 = 0;
|
||||
public const KEY_E1 = 224;
|
||||
|
||||
// Supported scan scodes.
|
||||
public const KEY_F1 = 59;
|
||||
public const KEY_F2 = 60;
|
||||
public const KEY_F3 = 61;
|
||||
public const KEY_F4 = 62;
|
||||
public const KEY_F5 = 63;
|
||||
public const KEY_F6 = 64;
|
||||
public const KEY_F7 = 65;
|
||||
public const KEY_F8 = 66;
|
||||
public const KEY_F9 = 67;
|
||||
public const KEY_F10 = 68;
|
||||
public const KEY_F11 = 87;
|
||||
public const KEY_F12 = 88;
|
||||
public const KEY_UP = 72;
|
||||
public const KEY_LEFT = 75;
|
||||
public const KEY_RIGHT = 77;
|
||||
public const KEY_DOWN = 80;
|
||||
public const KEY_DELETE = 83;
|
||||
public const KEY_HOME = 71;
|
||||
public const KEY_PAGEUP = 73;
|
||||
public const KEY_END = 79;
|
||||
public const KEY_PAGEDOWN = 81;
|
||||
public const KEY_INSERT = 82;
|
||||
|
||||
private const LINUX_LIBRARY = __DIR__.'/Resources/libgetch.so';
|
||||
private const WINDOWS_LIBRARY = 'ucrtbase.dll';
|
||||
|
|
|
@ -13,10 +13,16 @@
|
|||
#include <linux/input.h>
|
||||
#include <glob.h>
|
||||
|
||||
#define EVENT_DEVICE_GLOB "/dev/input/by-path/*-event-kbd"
|
||||
|
||||
#define FKEY(k) ((k) >= KEY_F1 && (k) <= KEY_F10) || (k) == KEY_F12 || (k) == KEY_F11
|
||||
#define NOTNUMPAD(k) ((k) >= KEY_HOME && (k) <= KEY_DELETE)
|
||||
|
||||
#define EVENT_DEVICE_GLOB "/dev/input/by-path/*-event-kbd"
|
||||
#define XOR_SWAP(a,b) do\
|
||||
{\
|
||||
(a) ^= (b);\
|
||||
(b) ^= (a);\
|
||||
(a) ^= (b);\
|
||||
} while (0)
|
||||
|
||||
static struct termios oldTermAttributes;
|
||||
|
||||
|
@ -26,24 +32,12 @@ inline static void reverseString(char * str)
|
|||
{
|
||||
char * end = str + strlen(str) - 1;
|
||||
|
||||
// swap the values in the two given variables
|
||||
// XXX: fails when a and b refer to same memory location
|
||||
# define XOR_SWAP(a,b) do\
|
||||
{\
|
||||
(a) ^= (b);\
|
||||
(b) ^= (a);\
|
||||
(a) ^= (b);\
|
||||
} while (0)
|
||||
|
||||
// walk inwards from both ends of the string,
|
||||
// swapping until we get to the middle
|
||||
while (str < end)
|
||||
{
|
||||
XOR_SWAP(*str, *end);
|
||||
str++;
|
||||
end--;
|
||||
}
|
||||
# undef XOR_SWAP
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +97,7 @@ static int getEventDevice(char ** device)
|
|||
|
||||
static unsigned short getScanCode()
|
||||
{
|
||||
struct input_event inputEvent[40];
|
||||
struct input_event inputEvent[5];
|
||||
int eventDevice;
|
||||
|
||||
char *device;
|
||||
|
@ -129,12 +123,7 @@ static unsigned short getScanCode()
|
|||
|
||||
close(eventDevice);
|
||||
|
||||
// for(int i = 0;i<39;i++) {
|
||||
// printf("Type %d, Code %d, Value %d\r\n", inputEvent[i].type, inputEvent[i].code, inputEvent[i].value);
|
||||
// }
|
||||
|
||||
for(int i = 0;i<40;i++) {
|
||||
//printf("Type %d, Code %d\n", inputEvent[i].type, inputEvent[i].code);
|
||||
for(int i = 0;i<5;i++) {
|
||||
if(inputEvent[i].type == EV_KEY && inputEvent[i].code != KEY_ENTER) {
|
||||
return inputEvent[i].code;
|
||||
}
|
||||
|
@ -212,17 +201,12 @@ static int readKey(void) {
|
|||
case KEY_KP6: // RIGHT
|
||||
case KEY_KP7: // HOME
|
||||
case KEY_KP8: // UP
|
||||
//getchar();
|
||||
//getchar();
|
||||
discardBytes = 2;
|
||||
break;
|
||||
case KEY_KP0: // INSERT
|
||||
case KEY_KPDOT: // DELETE
|
||||
case KEY_KP9: // PAGEUP
|
||||
case KEY_KP3: // PAGEDOWN
|
||||
/*getchar();
|
||||
getchar();
|
||||
getchar(); */
|
||||
discardBytes = 3;
|
||||
break;
|
||||
case KEY_F5:
|
||||
|
@ -233,10 +217,6 @@ static int readKey(void) {
|
|||
case KEY_F10:
|
||||
case KEY_F11:
|
||||
case KEY_F12:
|
||||
/* getchar();
|
||||
getchar();
|
||||
getchar();
|
||||
getchar(); */
|
||||
discardBytes = 4;
|
||||
break;
|
||||
|
||||
|
@ -269,11 +249,21 @@ int _getch(void) {
|
|||
return key;
|
||||
}
|
||||
|
||||
int getch(void)
|
||||
{
|
||||
return _getch();
|
||||
}
|
||||
|
||||
int _ungetch(int ch)
|
||||
{
|
||||
return ungetc(ch, stdin);
|
||||
}
|
||||
|
||||
int ungetch(int ch)
|
||||
{
|
||||
return _ungetch(ch);
|
||||
}
|
||||
|
||||
int *cinPeekCount(ushort count)
|
||||
{
|
||||
char buffer[count];
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue