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
17 #include "wine/keyboard16.h"
23 #include "debugtools.h"
27 DECLARE_DEBUG_CHANNEL(event)
28 DECLARE_DEBUG_CHANNEL(keyboard)
30 /**********************************************************************/
32 KEYBOARD_DRIVER *KEYBOARD_Driver = NULL;
34 static LPKEYBD_EVENT_PROC DefKeybEventProc = NULL;
35 LPBYTE pKeyStateTable = NULL;
37 /***********************************************************************
38 * KEYBOARD_Inquire (KEYBOARD.1)
40 WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo)
42 kbInfo->Begin_First_Range = 0;
43 kbInfo->End_First_Range = 0;
44 kbInfo->Begin_Second_Range = 0;
45 kbInfo->End_Second_Range = 0;
46 kbInfo->StateSize = 16;
48 return sizeof(KBINFO);
51 /***********************************************************************
52 * KEYBOARD_Enable (KEYBOARD.2)
54 VOID WINAPI KEYBOARD_Enable( LPKEYBD_EVENT_PROC lpKeybEventProc,
57 static BOOL initDone = FALSE;
59 DefKeybEventProc = lpKeybEventProc;
60 pKeyStateTable = lpKeyState;
62 /* all states to false */
63 memset( lpKeyState, 0, sizeof(lpKeyState) );
65 if (!initDone) KEYBOARD_Driver->pInit();
69 /***********************************************************************
70 * KEYBOARD_Disable (KEYBOARD.3)
72 VOID WINAPI KEYBOARD_Disable(VOID)
74 DefKeybEventProc = NULL;
75 pKeyStateTable = NULL;
78 /***********************************************************************
81 void KEYBOARD_SendEvent( BYTE bVk, BYTE bScan, DWORD dwFlags,
82 DWORD posX, DWORD posY, DWORD time )
87 if ( !DefKeybEventProc ) return;
89 TRACE( event, "(%d,%d,%04lX)\n", bVk, bScan, dwFlags );
91 wke.magic = WINE_KEYBDEVENT_MAGIC;
96 /* To avoid deadlocks, we have to suspend all locks on windows structures
97 before the program control is passed to the keyboard driver */
98 iWndsLocks = WIN_SuspendWndsLock();
99 DefKeybEventProc( bVk, bScan, dwFlags, (DWORD)&wke );
100 WIN_RestoreWndsLock(iWndsLocks);
103 /**********************************************************************
104 * ScreenSwitchEnable (KEYBOARD.100)
106 VOID WINAPI ScreenSwitchEnable16(WORD unused)
108 FIXME(keyboard,"(%04x): stub\n",unused);
111 /**********************************************************************
112 * OemKeyScan (KEYBOARD.128)(USER32.401)
114 DWORD WINAPI OemKeyScan(WORD wOemChar)
116 TRACE(keyboard,"*OemKeyScan (%d)\n",wOemChar);
121 /**********************************************************************
122 * VkKeyScan [KEYBOARD.129]
124 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
125 * for the current keyboard.
126 * high-order byte yields :
130 * 3-5 Shift-key combinations that are not used for characters
133 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
134 * FIXME : works ok except for dead chars :
135 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
136 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
139 WORD WINAPI VkKeyScan16(CHAR cChar)
141 return KEYBOARD_Driver->pVkKeyScan(cChar);
144 /******************************************************************************
145 * GetKeyboardType16 (KEYBOARD.130)
147 INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
149 TRACE(keyboard,"(%d)\n",nTypeFlag);
152 case 0: /* Keyboard type */
153 return 4; /* AT-101 */
155 case 1: /* Keyboard Subtype */
156 return 0; /* There are no defined subtypes */
158 case 2: /* Number of F-keys */
159 return 12; /* We're doing an 101 for now, so return 12 F-keys */
162 WARN(keyboard, "Unknown type\n");
163 return 0; /* The book says 0 here, so 0 */
167 /******************************************************************************
168 * MapVirtualKey16 (KEYBOARD.131)
170 * MapVirtualKey translates keycodes from one format to another
172 UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
174 return KEYBOARD_Driver->pMapVirtualKey(wCode,wMapType);
177 /****************************************************************************
178 * GetKBCodePage16 (KEYBOARD.132)
180 INT16 WINAPI GetKBCodePage16(void)
182 TRACE(keyboard,"(void)\n");
186 /****************************************************************************
187 * GetKeyNameText16 (KEYBOARD.133)
189 INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
191 return KEYBOARD_Driver->pGetKeyNameText(lParam, lpBuffer, nSize);
194 /****************************************************************************
195 * ToAscii (KEYBOARD.4)
197 * The ToAscii function translates the specified virtual-key code and keyboard
198 * state to the corresponding Windows character or characters.
200 * If the specified key is a dead key, the return value is negative. Otherwise,
201 * it is one of the following values:
203 * 0 The specified virtual key has no translation for the current state of the keyboard.
204 * 1 One Windows character was copied to the buffer.
205 * 2 Two characters were copied to the buffer. This usually happens when a
206 * dead-key character (accent or diacritic) stored in the keyboard layout cannot
207 * be composed with the specified virtual key to form a single character.
209 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
212 INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState,
213 LPVOID lpChar, UINT16 flags)
215 return KEYBOARD_Driver->pToAscii(
216 virtKey, scanCode, lpKeyState, lpChar, flags
220 /***********************************************************************
221 * KEYBOARD_GetBeepActive
223 BOOL KEYBOARD_GetBeepActive()
225 return KEYBOARD_Driver->pGetBeepActive();
228 /***********************************************************************
229 * KEYBOARD_SetBeepActive
231 void KEYBOARD_SetBeepActive(BOOL bActivate)
233 KEYBOARD_Driver->pSetBeepActive(bActivate);
236 /***********************************************************************
239 void KEYBOARD_Beep(void)
241 KEYBOARD_Driver->pBeep();