diff --git a/polymer/build/include/baselayer.h b/polymer/build/include/baselayer.h index 70c36f026..dc388a2c5 100644 --- a/polymer/build/include/baselayer.h +++ b/polymer/build/include/baselayer.h @@ -66,6 +66,7 @@ extern char inputdevices; #define KEYFIFOSIZ 64 extern char keystatus[256], keyfifo[KEYFIFOSIZ], keyfifoplc, keyfifoend; extern unsigned char keyasciififo[KEYFIFOSIZ], keyasciififoplc, keyasciififoend; +extern char scantoasc[128]; // mouse extern volatile int mousex, mousey, mouseb; diff --git a/polymer/build/include/osd.h b/polymer/build/include/osd.h index 4c56bcdb7..e7b0c58ee 100644 --- a/polymer/build/include/osd.h +++ b/polymer/build/include/osd.h @@ -31,7 +31,8 @@ const char *stripcolorcodes(const char *t); #define OSDCMD_OK 0 #define OSDCMD_SHOWHELP 1 -int osdexecscript; +extern int osdexecscript; +extern int osdkey; int OSD_Exec(const char *szScript); @@ -65,7 +66,8 @@ void OSD_CaptureKey(int sc); // handles keyboard input when capturing input. returns 0 if key was handled // or the scancode if it should be handled by the game. -int OSD_HandleKey(int sc, int press); +int OSD_HandleScanCode(int sc, int press); +int OSD_HandleChars(void); // handles the readjustment when screen resolution changes void OSD_ResizeDisplay(int w,int h); diff --git a/polymer/build/src/baselayer.c b/polymer/build/src/baselayer.c index 4de229c49..2ddbdb566 100644 --- a/polymer/build/src/baselayer.c +++ b/polymer/build/src/baselayer.c @@ -7,6 +7,18 @@ #include "winlayer.h" #endif +char scantoasc[128] = +{ + 0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0, + 'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s', + 'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v', + 'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0, + 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', + '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; + #ifdef USE_OPENGL struct glinfo glinfo = { diff --git a/polymer/build/src/osd.c b/polymer/build/src/osd.c index faf385688..bee8abd60 100644 --- a/polymer/build/src/osd.c +++ b/polymer/build/src/osd.c @@ -52,7 +52,7 @@ static char osdinput=0; // capture input? static int osdhead=0; // topmost visible line number static BFILE *osdlog=NULL; // log filehandle static char osdinited=0; // text buffer initialized? -static int osdkey=0x29; // tilde shows the osd +int osdkey=0x29; // tilde shows the osd static int keytime=0; static int osdscrtime = 0; @@ -648,50 +648,22 @@ static int OSD_FindDiffPoint(const char *str1, const char *str2) // Returns 0 if the key was handled internally, or the scancode if it should // be passed on to the game. // -int OSD_HandleKey(int sc, int press) + +int OSD_HandleChars(void) { - char ch; int i,j; symbol_t *tabc = NULL; static symbol_t *lastmatch = NULL; + char ch; - if (!osdinited) return sc; + if (!osdinited) return 1; - if (sc == osdkey) - { - if (press) - { - osdscroll = -osdscroll; - if (osdrowscur == -1) - osdscroll = 1; - else if (osdrowscur == osdrows) - osdscroll = -1; - osdrowscur += osdscroll; - OSD_CaptureInput(osdscroll == 1); - osdscrtime = getticks(); - } - return 0;//sc; - } - else if (!osdinput) - { - return sc; - } - - if (!press) - { - if (sc == 42 || sc == 54) // shift - osdeditshift = 0; - if (sc == 29 || sc == 157) // control - osdeditcontrol = 0; - return 0;//sc; - } - - keytime = gettime(); - - if (sc != 15) lastmatch = NULL; // tab + if (!osdinput) + return 1; while ((ch = bgetchar())) { + if (ch != 9) lastmatch = NULL; // tab if (ch == 1) // control a. jump to beginning of line { } @@ -706,7 +678,7 @@ int OSD_HandleKey(int sc, int press) } else if (ch == 8 || ch == 127) // control h, backspace { - if (!osdeditcursor || !osdeditlen) return 0; + if (!osdeditcursor || !osdeditlen) continue; if (!osdovertype) { if (osdeditcursor < osdeditlen) @@ -887,7 +859,7 @@ int OSD_HandleKey(int sc, int press) else if (ch >= 32) // text char { if (!osdovertype && osdeditlen == EDITLENGTH) // buffer full, can't insert another char - return 0; + continue; if (!osdovertype) { @@ -905,6 +877,43 @@ int OSD_HandleKey(int sc, int press) if (osdeditcursor>osdeditwinend) osdeditwinstart++,osdeditwinend++; } } + return 0; +} + +int OSD_HandleScanCode(int sc, int press) +{ + if (!osdinited) return sc; + + if (sc == osdkey) + { + if (press) + { + osdscroll = -osdscroll; + if (osdrowscur == -1) + osdscroll = 1; + else if (osdrowscur == osdrows) + osdscroll = -1; + osdrowscur += osdscroll; + OSD_CaptureInput(osdscroll == 1); + osdscrtime = getticks(); + } + return 0;//sc; + } + else if (!osdinput) + { + return sc; + } + + if (!press) + { + if (sc == 42 || sc == 54) // shift + osdeditshift = 0; + if (sc == 29 || sc == 157) // control + osdeditcontrol = 0; + return 0;//sc; + } + + keytime = gettime(); if (sc == 15) // tab { diff --git a/polymer/build/src/sdlayer.c b/polymer/build/src/sdlayer.c index 666aa9c9b..98627f043 100644 --- a/polymer/build/src/sdlayer.c +++ b/polymer/build/src/sdlayer.c @@ -1416,16 +1416,17 @@ int handleevents(void) case SDL_KEYUP: code = keytranslation[ev.key.keysym.sym]; - if (ev.key.keysym.unicode != 0 && ev.key.type == SDL_KEYDOWN && + if (code != osdkey && ev.key.keysym.unicode != 0 && ev.key.type == SDL_KEYDOWN && (ev.key.keysym.unicode & 0xff80) == 0 && ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) { keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f; keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); + OSD_HandleChars(); } // hook in the osd - if (OSD_HandleKey(code, (ev.key.type == SDL_KEYDOWN)) == 0) + if (OSD_HandleScanCode(code, (ev.key.type == SDL_KEYDOWN)) == 0) break; if (ev.key.type == SDL_KEYDOWN) diff --git a/polymer/build/src/winlayer.c b/polymer/build/src/winlayer.c index 81f48967f..54a7600bd 100644 --- a/polymer/build/src/winlayer.c +++ b/polymer/build/src/winlayer.c @@ -799,6 +799,7 @@ int bkbhit(void) void bflushchars(void) { + Bmemset(&keyasciififo,0,sizeof(keyasciififo)); keyasciififoplc = keyasciififoend = 0; } @@ -1043,7 +1044,7 @@ void releaseallbuttons(void) { //if (!keystatus[i]) continue; //if (OSD_HandleKey(i, 0) != 0) { - OSD_HandleKey(i, 0); + OSD_HandleScanCode(i, 0); SetKey(i, 0); if (keypresscallback) keypresscallback(i, 0); //} @@ -1648,7 +1649,7 @@ static void ProcessInputDevices(void) //if (IsDebuggerPresent() && k == DIK_F12) continue; // hook in the osd - if (OSD_HandleKey(k, (didod[i].dwData & 0x80)) != 0) + if (OSD_HandleScanCode(k, (didod[i].dwData & 0x80)) != 0) { SetKey(k, (didod[i].dwData & 0x80) == 0x80); @@ -1726,14 +1727,14 @@ static void ProcessInputDevices(void) u = (1000 + t - lastKeyTime)%1000; if ((u >= 250) && !(lastKeyDown&0x80000000l)) { - if (OSD_HandleKey(lastKeyDown, 1) != 0) + if (OSD_HandleScanCode(lastKeyDown, 1) != 0) SetKey(lastKeyDown, 1); lastKeyDown |= 0x80000000l; lastKeyTime = t; } else if ((u >= 30) && (lastKeyDown&0x80000000l)) { - if (OSD_HandleKey(lastKeyDown&(0x7fffffffl), 1) != 0) + if (OSD_HandleScanCode(lastKeyDown&(0x7fffffffl), 1) != 0) SetKey(lastKeyDown&(0x7fffffffl), 1); lastKeyTime = t; } @@ -4123,8 +4124,10 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA case WM_CHAR: if (((keyasciififoend+1)&(KEYFIFOSIZ-1)) == keyasciififoplc) return 0; if ((keyasciififoend - keyasciififoplc) > 0) return 0; + if (Btolower(scantoasc[osdkey]) == Btolower((unsigned char)wParam)) return 0; keyasciififo[keyasciififoend] = (unsigned char)wParam; keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); + OSD_HandleChars(); //OSD_Printf("WM_CHAR %d, %d-%d\n",wParam,keyasciififoplc,keyasciififoend); return 0;