4 * Copyright 1993 Bob Amstadt
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1997 David Faure
7 * Copyright 1998 Morten Welinder
8 * Copyright 1998 Ulrich Weigand
24 #include "debugtools.h"
28 static LPKEYBD_EVENT_PROC DefKeybEventProc = NULL;
29 LPBYTE pKeyStateTable = NULL;
31 #ifndef X_DISPLAY_MISSING
32 extern KEYBOARD_DRIVER X11DRV_KEYBOARD_Driver;
33 #else /* X_DISPLAY_MISSING */
34 extern KEYBOARD_DRIVER TTYDRV_KEYBOARD_Driver;
35 #endif /* X_DISPLAY_MISSING */
37 /***********************************************************************
40 KEYBOARD_DRIVER *KEYBOARD_GetDriver()
42 #ifndef X_DISPLAY_MISSING
43 return &X11DRV_KEYBOARD_Driver;
44 #else /* X_DISPLAY_MISSING */
45 return &TTYDRV_KEYBOARD_Driver;
46 #endif /* X_DISPLAY_MISSING */
49 /***********************************************************************
50 * KEYBOARD_Inquire (KEYBOARD.1)
52 WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo)
54 kbInfo->Begin_First_Range = 0;
55 kbInfo->End_First_Range = 0;
56 kbInfo->Begin_Second_Range = 0;
57 kbInfo->End_Second_Range = 0;
58 kbInfo->StateSize = 16;
60 return sizeof(KBINFO);
63 /***********************************************************************
64 * KEYBOARD_Enable (KEYBOARD.2)
66 VOID WINAPI KEYBOARD_Enable( LPKEYBD_EVENT_PROC lpKeybEventProc,
69 static BOOL32 initDone = FALSE;
71 DefKeybEventProc = lpKeybEventProc;
72 pKeyStateTable = lpKeyState;
74 /* all states to false */
75 memset( lpKeyState, 0, sizeof(lpKeyState) );
77 if (!initDone) KEYBOARD_GetDriver()->pInit();
81 /***********************************************************************
82 * KEYBOARD_Disable (KEYBOARD.3)
84 VOID WINAPI KEYBOARD_Disable(VOID)
86 DefKeybEventProc = NULL;
87 pKeyStateTable = NULL;
90 /***********************************************************************
93 void KEYBOARD_SendEvent( BYTE bVk, BYTE bScan, DWORD dwFlags,
94 DWORD posX, DWORD posY, DWORD time )
98 if ( !DefKeybEventProc ) return;
100 TRACE( event, "(%d,%d,%04lX)\n", bVk, bScan, dwFlags );
102 wke.magic = WINE_KEYBDEVENT_MAGIC;
107 DefKeybEventProc( bVk, bScan, dwFlags, (DWORD)&wke );
110 /**********************************************************************
111 * ScreenSwitchEnable (KEYBOARD.100)
113 VOID WINAPI ScreenSwitchEnable(WORD unused)
115 FIXME(keyboard,"(%04x): stub\n",unused);
118 /**********************************************************************
119 * OemKeyScan (KEYBOARD.128)(USER32.401)
121 DWORD WINAPI OemKeyScan(WORD wOemChar)
123 TRACE(keyboard,"*OemKeyScan (%d)\n",wOemChar);
128 /**********************************************************************
129 * VkKeyScan [KEYBOARD.129]
131 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
132 * for the current keyboard.
133 * high-order byte yields :
137 * 3-5 Shift-key combinations that are not used for characters
140 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
141 * FIXME : works ok except for dead chars :
142 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
143 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
146 WORD WINAPI VkKeyScan16(CHAR cChar)
148 return KEYBOARD_GetDriver()->pVkKeyScan(cChar);
151 /******************************************************************************
152 * GetKeyboardType16 (KEYBOARD.130)
154 INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
156 TRACE(keyboard,"(%d)\n",nTypeFlag);
159 case 0: /* Keyboard type */
160 return 4; /* AT-101 */
162 case 1: /* Keyboard Subtype */
163 return 0; /* There are no defined subtypes */
165 case 2: /* Number of F-keys */
166 return 12; /* We're doing an 101 for now, so return 12 F-keys */
169 WARN(keyboard, "Unknown type\n");
170 return 0; /* The book says 0 here, so 0 */
174 /******************************************************************************
175 * MapVirtualKey16 (KEYBOARD.131)
177 * MapVirtualKey translates keycodes from one format to another
179 UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
181 return KEYBOARD_GetDriver()->pMapVirtualKey(wCode,wMapType);
184 /****************************************************************************
185 * GetKBCodePage16 (KEYBOARD.132)
187 INT16 WINAPI GetKBCodePage16(void)
189 TRACE(keyboard,"(void)\n");
193 /****************************************************************************
194 * GetKeyNameText16 (KEYBOARD.133)
196 INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
198 return KEYBOARD_GetDriver()->pGetKeyNameText(lParam, lpBuffer, nSize);
201 /****************************************************************************
202 * ToAscii (KEYBOARD.4)
204 * The ToAscii function translates the specified virtual-key code and keyboard
205 * state to the corresponding Windows character or characters.
207 * If the specified key is a dead key, the return value is negative. Otherwise,
208 * it is one of the following values:
210 * 0 The specified virtual key has no translation for the current state of the keyboard.
211 * 1 One Windows character was copied to the buffer.
212 * 2 Two characters were copied to the buffer. This usually happens when a
213 * dead-key character (accent or diacritic) stored in the keyboard layout cannot
214 * be composed with the specified virtual key to form a single character.
216 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
219 INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState,
220 LPVOID lpChar, UINT16 flags)
222 return KEYBOARD_GetDriver()->pToAscii(
223 virtKey, scanCode, lpKeyState, lpChar, flags