1 /* ----------- console.c ---------- */
3 // #define WIN32_LEAN_AND_MEAN
7 #include "dflat32/dflat.h"
10 /* ----- table of alt keys for finding shortcut keys ----- */
12 static int altconvert
[] = {
13 ALT_A
,ALT_B
,ALT_C
,ALT_D
,ALT_E
,ALT_F
,ALT_G
,ALT_H
,
14 ALT_I
,ALT_J
,ALT_K
,ALT_L
,ALT_M
,ALT_N
,ALT_O
,ALT_P
,
15 ALT_Q
,ALT_R
,ALT_S
,ALT_T
,ALT_U
,ALT_V
,ALT_W
,ALT_X
,
16 ALT_Y
,ALT_Z
,ALT_0
,ALT_1
,ALT_2
,ALT_3
,ALT_4
,ALT_5
,
17 ALT_6
,ALT_7
,ALT_8
,ALT_9
21 static COORD cursorpos
[MAXSAVES
];
22 static CONSOLE_CURSOR_INFO cursorinfo
[MAXSAVES
];
26 void SwapCursorStack(void)
31 CONSOLE_CURSOR_INFO csi
;
33 coord
= cursorpos
[cs
-2];
34 cursorpos
[cs
-2] = cursorpos
[cs
-1];
35 cursorpos
[cs
-1] = coord
;
39 sizeof(CONSOLE_CURSOR_INFO
));
40 memcpy (&cursorinfo
[cs
-2],
42 sizeof(CONSOLE_CURSOR_INFO
));
43 memcpy (&cursorinfo
[cs
-1],
45 sizeof(CONSOLE_CURSOR_INFO
));
50 /* ---- Read a keystroke ---- */
51 void GetKey (PINPUT_RECORD lpBuffer
)
56 hInput
= GetStdHandle (STD_INPUT_HANDLE
);
60 // WaitForSingleObject (hInput, INFINITE);
61 ReadConsoleInput (hInput
, lpBuffer
, 1, &dwRead
);
62 if ((lpBuffer
->EventType
== KEY_EVENT
) &&
63 (lpBuffer
->Event
.KeyEvent
.bKeyDown
== TRUE
))
70 /* ---------- read the keyboard shift status --------- */
75 // int86(KEYBRD, ®s, ®s);
83 /* -------- sound a buzz tone ---------- */
91 /* ------ position the cursor ------ */
92 void cursor(int x
, int y
)
98 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE
), coPos
);
102 /* ------- get the current cursor position ------- */
103 void curr_cursor(int *x
, int *y
)
104 //VOID GetCursorXY (PSHORT x, PSHORT y)
106 CONSOLE_SCREEN_BUFFER_INFO csbi
;
108 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE
), &csbi
);
110 *x
= (int)csbi
.dwCursorPosition
.X
;
111 *y
= (int)csbi
.dwCursorPosition
.Y
;
115 /* ------ save the current cursor configuration ------ */
116 void savecursor(void)
120 CONSOLE_SCREEN_BUFFER_INFO csbi
;
122 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE
), &csbi
);
123 cursorpos
[cs
].X
= csbi
.dwCursorPosition
.X
;
124 cursorpos
[cs
].Y
= csbi
.dwCursorPosition
.Y
;
126 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
133 /* ---- restore the saved cursor configuration ---- */
134 void restorecursor(void)
139 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE
),
141 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
146 /* ------ make a normal cursor ------ */
147 void normalcursor(void)
149 CONSOLE_CURSOR_INFO csi
;
153 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
157 /* ------ hide the cursor ------ */
158 void hidecursor(void)
160 CONSOLE_CURSOR_INFO csi
;
162 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
164 csi
.bVisible
= FALSE
;
165 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
169 /* ------ unhide the cursor ------ */
170 void unhidecursor(void)
172 CONSOLE_CURSOR_INFO csi
;
174 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
177 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
181 /* set the cursor size (in percent) */
182 void set_cursor_size (unsigned t
)
184 CONSOLE_CURSOR_INFO csi
;
186 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
195 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
200 /* ------ convert an Alt+ key to its letter equivalent ----- */
201 int AltConvert(int c
)
206 for (i
= 0; i
< 36; i
++)
207 if (c
== altconvert
[i
])