2 * Copyright (C) 1984-2019 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information, see the README file.
12 * Routines dealing with getting input from the keyboard (i.e. from the user).
20 #if MSDOS_COMPILER==WIN32C
21 #define WIN32_LEAN_AND_MEAN
23 #define _WIN32_WINNT 0x400
26 static DWORD console_mode;
33 extern int wheel_lines;
36 * Open keyboard for input.
39 open_getchr(VOID_PARAM)
41 #if MSDOS_COMPILER==WIN32C
42 /* Need this to let child processes inherit our console handle */
43 SECURITY_ATTRIBUTES sa;
44 memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
45 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
46 sa.bInheritHandle = TRUE;
47 tty = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
49 OPEN_EXISTING, 0L, NULL);
50 GetConsoleMode(tty, &console_mode);
51 /* Make sure we get Ctrl+C events. */
52 SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
57 * Open a new handle to CON: in binary mode
58 * for unbuffered keyboard read.
62 tty = open("CON", OPEN_READ);
63 #if MSDOS_COMPILER==DJGPPC
65 * Setting stdin to binary causes Ctrl-C to not
66 * raise SIGINT. We must undo that side-effect.
68 (void) __djgpp_set_ctrl_c(1);
73 * If that doesn't work, use file descriptor 2,
74 * which in Unix is usually attached to the screen,
75 * but also usually lets you read from the keyboard.
78 /* The __open() system call translates "/dev/tty" to "con". */
79 tty = __open("/dev/tty", OPEN_READ);
81 tty = open("/dev/tty", OPEN_READ);
93 close_getchr(VOID_PARAM)
95 #if MSDOS_COMPILER==WIN32C
96 SetConsoleMode(tty, console_mode);
101 #if MSDOS_COMPILER==WIN32C
103 * Close the pipe, restoring the keyboard (CMD resets it, losing the mouse).
112 SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
118 * Get the number of lines to scroll when mouse wheel is moved.
121 default_wheel_lines(VOID_PARAM)
124 #if MSDOS_COMPILER==WIN32C
125 if (SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &lines, 0))
127 if (lines == WHEEL_PAGESCROLL)
135 * Get a character from the keyboard.
145 #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC
147 * In raw read, we don't see ^C so look here for it.
150 #if MSDOS_COMPILER==WIN32C
163 result = iread(tty, &uc, sizeof(char));
166 if (result == READ_INTR)
171 * Don't call error() here,
172 * because error calls getchr!
177 #if 0 /* allow entering arbitrary hex chars for testing */
178 /* ctrl-A followed by two hex chars makes a byte */
180 static int hex_in = 0;
181 static int hex_value = 0;
182 if (c == CONTROL('A'))
191 if (c >= '0' && c <= '9')
193 else if (c >= 'a' && c <= 'f')
195 else if (c >= 'A' && c <= 'F')
199 hex_value = (hex_value << 4) | v;
210 * Various parts of the program cannot handle
211 * an input character of '\0'.
212 * If a '\0' was actually typed, convert it to '\340' here.
216 } while (result != 1);