| 1 | /* $Id: oslibkbd.cpp,v 1.1 2003-02-16 15:31:10 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Keyboard helpers for OS/2 | 
|---|
| 4 | * | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 2003 Sander van Leeuwen (sandervl@innotek.de) | 
|---|
| 7 | * | 
|---|
| 8 | * | 
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 10 | * | 
|---|
| 11 | */ | 
|---|
| 12 | #define  INCL_WIN | 
|---|
| 13 | #define  INCL_PM | 
|---|
| 14 | #define  INCL_WINSWITCHLIST | 
|---|
| 15 | #define  INCL_WININPUT | 
|---|
| 16 | #include <os2wrap.h> | 
|---|
| 17 | #include <stdlib.h> | 
|---|
| 18 | #include <stdio.h> | 
|---|
| 19 | #include <string.h> | 
|---|
| 20 |  | 
|---|
| 21 | #include <dbglog.h> | 
|---|
| 22 | #include <win32type.h> | 
|---|
| 23 | #include <winconst.h> | 
|---|
| 24 |  | 
|---|
| 25 | #define DBG_LOCALLOG    DBG_oslibkbd | 
|---|
| 26 | #include "dbglocal.h" | 
|---|
| 27 |  | 
|---|
| 28 | #ifdef __EMX__ | 
|---|
| 29 |  | 
|---|
| 30 | USHORT _THUNK_FUNCTION (Win16GetScanState) (); | 
|---|
| 31 | USHORT APIENTRY WinGetScanState (HWND hwnd, USHORT vk) | 
|---|
| 32 | { | 
|---|
| 33 | return ((USHORT) | 
|---|
| 34 | (_THUNK_PASCAL_PROLOG (4+2); | 
|---|
| 35 | _THUNK_PASCAL_LONG ((ULONG) hwnd); | 
|---|
| 36 | _THUNK_PASCAL_SHORT (vk); | 
|---|
| 37 | _THUNK_PASCAL_CALL (Win16GetScanState))); | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | USHORT _THUNK_FUNCTION (Win16SetScanStateTable) (); | 
|---|
| 41 | BOOL APIENTRY WinSetScanStateTable (HWND hwnd, PUCHAR pTable, BOOL bFlag) | 
|---|
| 42 | { | 
|---|
| 43 | return ((BOOL) | 
|---|
| 44 | (_THUNK_PASCAL_PROLOG (4+4+4); | 
|---|
| 45 | _THUNK_PASCAL_LONG ((ULONG) hwnd); | 
|---|
| 46 | _THUNK_PASCAL_FLAT ((void *) pTable); | 
|---|
| 47 | _THUNK_PASCAL_LONG (bFlag); | 
|---|
| 48 | _THUNK_PASCAL_CALL (Win16SetScanStateTable))); | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | #else | 
|---|
| 52 |  | 
|---|
| 53 | SHORT APIENTRY16 WinGetScanState( HWND, USHORT ); | 
|---|
| 54 | BOOL  APIENTRY16 WinSetScanStateTable(HWND,unsigned char *,BOOL); | 
|---|
| 55 |  | 
|---|
| 56 | #endif | 
|---|
| 57 |  | 
|---|
| 58 | //****************************************************************************** | 
|---|
| 59 | //****************************************************************************** | 
|---|
| 60 | SHORT OSLibWinGetScanState(USHORT scan) | 
|---|
| 61 | { | 
|---|
| 62 | SHORT state; | 
|---|
| 63 | SHORT sel; | 
|---|
| 64 |  | 
|---|
| 65 | sel = RestoreOS2FS(); | 
|---|
| 66 | state = WinGetScanState(HWND_DESKTOP, scan); | 
|---|
| 67 | SetFS(sel); | 
|---|
| 68 |  | 
|---|
| 69 | return state; | 
|---|
| 70 | } | 
|---|
| 71 | //****************************************************************************** | 
|---|
| 72 | //****************************************************************************** | 
|---|
| 73 | BOOL OSLibWinGetScanStateTable(unsigned char *PMScanState) | 
|---|
| 74 | { | 
|---|
| 75 | SHORT ret; | 
|---|
| 76 | SHORT sel; | 
|---|
| 77 |  | 
|---|
| 78 | sel = RestoreOS2FS(); | 
|---|
| 79 | ret = WinSetScanStateTable(HWND_DESKTOP, PMScanState, FALSE); | 
|---|
| 80 | SetFS(sel); | 
|---|
| 81 |  | 
|---|
| 82 | if(ret == FALSE) { | 
|---|
| 83 | dprintf(("WinSetScanStateTable failed with %x", WinGetLastError(0))); | 
|---|
| 84 | } | 
|---|
| 85 | return ret; | 
|---|
| 86 | } | 
|---|
| 87 | //****************************************************************************** | 
|---|
| 88 | //****************************************************************************** | 
|---|
| 89 | LONG OSLibWinGetPhysKeyState(LONG scan) | 
|---|
| 90 | { | 
|---|
| 91 | return WinGetPhysKeyState(HWND_DESKTOP,scan); | 
|---|
| 92 | } | 
|---|
| 93 | //****************************************************************************** | 
|---|
| 94 | //****************************************************************************** | 
|---|
| 95 | BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState) | 
|---|
| 96 | { | 
|---|
| 97 | return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, FALSE ); | 
|---|
| 98 | } | 
|---|
| 99 | //****************************************************************************** | 
|---|
| 100 | //****************************************************************************** | 
|---|
| 101 | BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState) | 
|---|
| 102 | { | 
|---|
| 103 | return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, TRUE ); | 
|---|
| 104 | } | 
|---|
| 105 | //****************************************************************************** | 
|---|
| 106 | //****************************************************************************** | 
|---|
| 107 | USHORT APIENTRY WinTranslateChar2( USHORT  /* Codepage (currently ignored) */ | 
|---|
| 108 | , PUSHORT /* Ptr to char to translate     */ | 
|---|
| 109 | , PULONG  /* Ptr to deadkey save info     */ | 
|---|
| 110 | , USHORT  /* Translation option (TC_xxx)  */ | 
|---|
| 111 | , PUSHORT /* Ptr to shift state (TCF_xxx) */ | 
|---|
| 112 | ); | 
|---|
| 113 | //****************************************************************************** | 
|---|
| 114 | //****************************************************************************** | 
|---|
| 115 | USHORT OSLibWinTranslateChar(USHORT usScanCode, ULONG type, USHORT shiftstate) | 
|---|
| 116 | { | 
|---|
| 117 | USHORT usResult; | 
|---|
| 118 | USHORT sel = GetFS(); | 
|---|
| 119 |  | 
|---|
| 120 | usResult = WinTranslateChar2(0, &usScanCode, NULL, type, &shiftstate); | 
|---|
| 121 | SetFS(sel); | 
|---|
| 122 | return usScanCode; | 
|---|
| 123 | } | 
|---|
| 124 | //****************************************************************************** | 
|---|
| 125 | //****************************************************************************** | 
|---|