1 /* ----------- console.c ---------- */
3 #define WIN32_LEAN_AND_MEAN
10 /* ----- table of alt keys for finding shortcut keys ----- */
12 static int altconvert
[] = {
13 DF_ALT_A
,DF_ALT_B
,DF_ALT_C
,DF_ALT_D
,DF_ALT_E
,DF_ALT_F
,DF_ALT_G
,DF_ALT_H
,
14 DF_ALT_I
,DF_ALT_J
,DF_ALT_K
,DF_ALT_L
,DF_ALT_M
,DF_ALT_N
,DF_ALT_O
,DF_ALT_P
,
15 DF_ALT_Q
,DF_ALT_R
,DF_ALT_S
,DF_ALT_T
,DF_ALT_U
,DF_ALT_V
,DF_ALT_W
,DF_ALT_X
,
16 DF_ALT_Y
,DF_ALT_Z
,DF_ALT_0
,DF_ALT_1
,DF_ALT_2
,DF_ALT_3
,DF_ALT_4
,DF_ALT_5
,
17 DF_ALT_6
,DF_ALT_7
,DF_ALT_8
,DF_ALT_9
21 static COORD cursorpos
[DF_MAXSAVES
];
22 static CONSOLE_CURSOR_INFO cursorinfo
[DF_MAXSAVES
];
26 void DfSwapCursorStack(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 DfGetKey (PINPUT_RECORD lpBuffer
)
56 DfInput
= GetStdHandle (STD_INPUT_HANDLE
);
60 // WaitForSingleObject (DfInput, INFINITE);
61 ReadConsoleInput (DfInput
, 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 DfCursor ------ */
92 void DfCursor(int x
, int y
)
98 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE
), coPos
);
102 /* ------- get the current DfCursor position ------- */
103 void DfCurrCursor(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 DfCursor configuration ------ */
116 void DfSaveCursor(void)
118 if (cs
< DF_MAXSAVES
)
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 DfCursor configuration ---- */
134 void DfRestoreCursor(void)
139 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE
),
141 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
146 /* ------ make a normal DfCursor ------ */
147 void DfNormalCursor(void)
149 CONSOLE_CURSOR_INFO csi
;
153 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
157 /* ------ hide the DfCursor ------ */
158 void DfHideCursor(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 DfCursor ------ */
170 void DfUnhideCursor(void)
172 CONSOLE_CURSOR_INFO csi
;
174 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
177 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE
),
181 /* set the DfCursor size (in percent) */
182 void DfSetCursorSize (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 DfAltConvert(int c
)
206 for (i
= 0; i
< 36; i
++)
207 if (c
== altconvert
[i
])