Skip to content

Commit 57fef23

Browse files
author
tthomps
committed
Create a keymap to map keyboard keys to their corresponding SDL_Scancode.
Remove focus from top window when a new window is added to the top.
1 parent 2443779 commit 57fef23

File tree

11 files changed

+114
-26
lines changed

11 files changed

+114
-26
lines changed

MapKeys.ahk

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
GUI, new
2+
Gui, Add, Edit, R20 w400 vMyEdit
3+
4+
letterVar = A
5+
var = `tMyOS_Keycodes[%letterVar%_PRESSED] = SDL_SCANCODE_%letterVar%;
6+
7+
Transform, numberVar, Asc, %letterVar%
8+
9+
Loop, 26
10+
{
11+
Transform, letterVar, Chr, %numberVar%
12+
var = %var%`n`tMyOS_Keycodes[%letterVar%_PRESSED] = SDL_SCANCODE_%letterVar%;
13+
numberVar += 1
14+
}
15+
16+
17+
18+
GuiControl,, MyEdit, %var%
19+
Gui, Show
20+
21+
~^s::
22+
Reload
23+
Exit

MyOS_1/Libs/SDL/src/video/myos/SDL_myosevents.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
3. This notice may not be removed or altered from any source distribution.
2020
*/
2121
#include "../../SDL_internal.h"
22+
#include "SDL_myoskeyboard.h"
2223

2324
#if SDL_VIDEO_DRIVER_MYOS
2425

@@ -49,9 +50,9 @@ MYOS_PumpEvents(_THIS)
4950
scancode = (0x7F & scancode);
5051

5152
if (keyRelease)
52-
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
53+
SDL_SendKeyboardKey(SDL_RELEASED, MyOS_Keycodes[scancode]);
5354
else
54-
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
55+
SDL_SendKeyboardKey(SDL_PRESSED, MyOS_Keycodes[scancode]);
5556
}
5657

5758
// Check for mouse motion
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
#include "../../SDL_internal.h"
3+
#include "SDL_MyOSkeyboard.h"
4+
#include "../../../Drivers/Keyboard.h"
5+
6+
SDL_Scancode MyOS_Keycodes[SDL_NUM_SCANCODES] = { SDL_SCANCODE_UNKNOWN };
7+
8+
void MyOS_InitKeyboard(void)
9+
{
10+
MyOS_Keycodes[A_PRESSED] = SDL_SCANCODE_A;
11+
MyOS_Keycodes[B_PRESSED] = SDL_SCANCODE_B;
12+
MyOS_Keycodes[C_PRESSED] = SDL_SCANCODE_C;
13+
MyOS_Keycodes[D_PRESSED] = SDL_SCANCODE_D;
14+
MyOS_Keycodes[E_PRESSED] = SDL_SCANCODE_E;
15+
MyOS_Keycodes[F_PRESSED] = SDL_SCANCODE_F;
16+
MyOS_Keycodes[G_PRESSED] = SDL_SCANCODE_G;
17+
MyOS_Keycodes[H_PRESSED] = SDL_SCANCODE_H;
18+
MyOS_Keycodes[I_PRESSED] = SDL_SCANCODE_I;
19+
MyOS_Keycodes[J_PRESSED] = SDL_SCANCODE_J;
20+
MyOS_Keycodes[K_PRESSED] = SDL_SCANCODE_K;
21+
MyOS_Keycodes[L_PRESSED] = SDL_SCANCODE_L;
22+
MyOS_Keycodes[M_PRESSED] = SDL_SCANCODE_M;
23+
MyOS_Keycodes[N_PRESSED] = SDL_SCANCODE_N;
24+
MyOS_Keycodes[O_PRESSED] = SDL_SCANCODE_O;
25+
MyOS_Keycodes[P_PRESSED] = SDL_SCANCODE_P;
26+
MyOS_Keycodes[Q_PRESSED] = SDL_SCANCODE_Q;
27+
MyOS_Keycodes[R_PRESSED] = SDL_SCANCODE_R;
28+
MyOS_Keycodes[S_PRESSED] = SDL_SCANCODE_S;
29+
MyOS_Keycodes[T_PRESSED] = SDL_SCANCODE_T;
30+
MyOS_Keycodes[U_PRESSED] = SDL_SCANCODE_U;
31+
MyOS_Keycodes[V_PRESSED] = SDL_SCANCODE_V;
32+
MyOS_Keycodes[W_PRESSED] = SDL_SCANCODE_W;
33+
MyOS_Keycodes[X_PRESSED] = SDL_SCANCODE_X;
34+
MyOS_Keycodes[Y_PRESSED] = SDL_SCANCODE_Y;
35+
MyOS_Keycodes[Z_PRESSED] = SDL_SCANCODE_Z;
36+
37+
MyOS_Keycodes[LEFT_BRACKET_PRESSED] = SDL_SCANCODE_LEFTBRACKET;
38+
MyOS_Keycodes[RIGHT_BRACKET_PRESSED] = SDL_SCANCODE_RIGHTBRACKET;
39+
MyOS_Keycodes[ENTER_PRESSED] = SDL_SCANCODE_RETURN;
40+
MyOS_Keycodes[COMMA_PRESSED] = SDL_SCANCODE_COMMA;
41+
MyOS_Keycodes[SPACE_PRESSED] = SDL_SCANCODE_SPACE;
42+
MyOS_Keycodes[BACKSP_PRESSED] = SDL_SCANCODE_BACKSPACE;
43+
MyOS_Keycodes[TAB_PRESSED] = SDL_SCANCODE_TAB;
44+
MyOS_Keycodes[PERIOD_PRESSED] = SDL_SCANCODE_PERIOD;
45+
MyOS_Keycodes[FORWARD_SLASH_PRESSED] = SDL_SCANCODE_SLASH;
46+
MyOS_Keycodes[BACK_SLASH_PRESSED] = SDL_SCANCODE_BACKSLASH;
47+
MyOS_Keycodes[BACK_TICK_PRESSED] = SDL_SCANCODE_GRAVE;
48+
MyOS_Keycodes[ONE_PRESSED] = SDL_SCANCODE_1;
49+
MyOS_Keycodes[TWO_PRESSED] = SDL_SCANCODE_2;
50+
MyOS_Keycodes[THREE_PRESSED] = SDL_SCANCODE_3;
51+
MyOS_Keycodes[FOUR_PRESSED] = SDL_SCANCODE_4;
52+
MyOS_Keycodes[FIVE_PRESSED] = SDL_SCANCODE_5;
53+
MyOS_Keycodes[SIX_PRESSED] = SDL_SCANCODE_6;
54+
MyOS_Keycodes[SEVEN_PRESSED] = SDL_SCANCODE_7;
55+
MyOS_Keycodes[EIGHT_PRESSED] = SDL_SCANCODE_8;
56+
MyOS_Keycodes[NINE_PRESSED] = SDL_SCANCODE_9;
57+
MyOS_Keycodes[ZERO_PRESSED] = SDL_SCANCODE_0;
58+
MyOS_Keycodes[HYPHEN_PRESSED] = '-';
59+
MyOS_Keycodes[EQUALS_PRESSED] = SDL_SCANCODE_EQUALS;
60+
MyOS_Keycodes[SEMI_PRESSED] = SDL_SCANCODE_SEMICOLON;
61+
MyOS_Keycodes[SINGLE_QUOTE_PRESSED] = SDL_SCANCODE_APOSTROPHE;
62+
63+
// TODO: There are certainly more keypresses that need to be translated
64+
}
65+
66+
/* vi: set ts=4 sw=4 expandtab: */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "../../SDL_internal.h"
2+
#include "../include/SDL_scancode.h"
3+
4+
extern SDL_Scancode MyOS_Keycodes[SDL_NUM_SCANCODES];
5+
6+
void MyOS_InitKeyboard(void);
7+
8+
/* vi: set ts=4 sw=4 expandtab: */

MyOS_1/Libs/SDL/src/video/myos/SDL_myosvideo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ MYOS_VideoInit(_THIS)
125125
SDL_zero(mode);
126126
SDL_AddDisplayMode(&_this->displays[0], &mode);
127127

128+
MyOS_InitKeyboard();
129+
128130
/* We're done! */
129131
return 0;
130132
}

MyOS_GUI_Shell/MyOS_GUI_Shell.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ void BringWindowToFront(GUI_WINDOW_STACK_ENTRY *pEntry)
170170
if (pStackTop == pEntry)
171171
return;
172172

173+
pStackTop->pWindow->LoseFocus();
174+
173175
// bridge the hole left by this window
174176
RemoveWindowFromStack(pEntry);
175177

@@ -215,6 +217,7 @@ void AddWindowToStack(GUI_Window *window, GUI_WINDOW_STACK_ENTRY *pStackEntry)
215217
{
216218
pStackEntry->pUnderneath = pStackTop;
217219
pStackTop->pAbove = pStackEntry;
220+
pStackTop->pWindow->LoseFocus();
218221
}
219222
else
220223
pStackEntry->pUnderneath = NULL;
@@ -231,32 +234,9 @@ GUI_Window *CreateTextWindow(uint32_t uniqueID, const char *windowName)
231234
if (!windowList[i])
232235
{
233236
windowList[i] = new GUI_TerminalWindow(windowName);
234-
//new GUI_Window(nextX, nextY, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT, windowName);
235237

236238
// TODO: Check for NULL
237239
windowIDs[i] = uniqueID;
238-
239-
// Advance position of next window
240-
/*nextX += WINDOW_X_INC;
241-
nextX %= MAX_WINDOW_X;
242-
nextY += WINDOW_Y_INC;
243-
nextY %= MAX_WINDOW_Y;
244-
245-
// set bg color and change color of next window
246-
SDL_Color bg;
247-
bg.r = bgRed;
248-
bg.b = bgBlue;
249-
bg.g = bgGreen;
250-
251-
windowList[i]->SetBackgroundColor(bg);
252-
253-
bgRed += BG_RED_INC;
254-
bgGreen += BG_GREEN_INC;
255-
bgBlue += BG_BLUE_INC;
256-
257-
bgRed %= 255;
258-
bgGreen %= 255;
259-
bgBlue %= 255;*/
260240

261241
AddWindowToStack(windowList[i], &windowStack[i]);
262242

@@ -556,7 +536,7 @@ int main(int argc, char* argv[])
556536
done = true;
557537
break;
558538
default:
559-
MessageBoxf("Key pressed", "Scan code: 0x%X - %c", event.key.keysym.scancode, event.key.keysym.sym);
539+
//MessageBoxf("Key pressed", "Scan code: 0x%X - %c", event.key.keysym.scancode, event.key.keysym.sym);
560540
if (pStackTop)
561541
pStackTop->pWindow->SendChar(event.key.keysym.sym);
562542
break;

MyOS_GUI_Shell/MyOS_GUI_Shell.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\dummy\SDL_nullvideo.c" />
249249
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myosevents.c" />
250250
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myosframebuffer.c" />
251+
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myoskeyboard.c" />
251252
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myosvideo.c" />
252253
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\SDL_blit.c" />
253254
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\SDL_blit_0.c" />

MyOS_GUI_Shell/MyOS_GUI_Shell.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@
369369
<ClCompile Include="GUI_EditControl.cpp">
370370
<Filter>Source Files</Filter>
371371
</ClCompile>
372+
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myoskeyboard.c">
373+
<Filter>Source Files\SDL</Filter>
374+
</ClCompile>
372375
</ItemGroup>
373376
<ItemGroup>
374377
<ClInclude Include="GUI_Object.h">

Release/MyOS_1.dll

0 Bytes
Binary file not shown.

SDL_TestApp1/SDL_TestApp1.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@
247247
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\dummy\SDL_nullvideo.c" />
248248
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myosevents.c" />
249249
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myosframebuffer.c" />
250+
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myoskeyboard.c" />
250251
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myosvideo.c" />
251252
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\SDL_blit.c" />
252253
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\SDL_blit_0.c" />

SDL_TestApp1/SDL_TestApp1.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@
330330
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myosevents.c">
331331
<Filter>Source Files\SDL</Filter>
332332
</ClCompile>
333+
<ClCompile Include="..\MyOS_1\Libs\SDL\src\video\myos\SDL_myoskeyboard.c">
334+
<Filter>Source Files\SDL</Filter>
335+
</ClCompile>
333336
</ItemGroup>
334337
<ItemGroup>
335338
<ClInclude Include="TestCpp.h">

0 commit comments

Comments
 (0)