Fixed Makefile up-to-date check to avoid relinking all the object
[wine/wine-kai.git] / windows / keyboard.c
blob9df57fa1e193cd8f247204be19db7ff5e9c2379b
1 /*
2 * KEYBOARD driver
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
12 #include "config.h"
14 #include <stdlib.h>
15 #include <string.h>
16 #include <ctype.h>
17 #include "winuser.h"
18 #include "wine/keyboard16.h"
19 #include "win.h"
20 #include "gdi.h"
21 #include "heap.h"
22 #include "keyboard.h"
23 #include "message.h"
24 #include "debug.h"
25 #include "debugtools.h"
26 #include "struct32.h"
27 #include "winerror.h"
29 static LPKEYBD_EVENT_PROC DefKeybEventProc = NULL;
30 LPBYTE pKeyStateTable = NULL;
32 #ifndef X_DISPLAY_MISSING
33 extern KEYBOARD_DRIVER X11DRV_KEYBOARD_Driver;
34 #else /* X_DISPLAY_MISSING */
35 extern KEYBOARD_DRIVER TTYDRV_KEYBOARD_Driver;
36 #endif /* X_DISPLAY_MISSING */
38 /***********************************************************************
39 * KEYBOARD_GetDriver
41 KEYBOARD_DRIVER *KEYBOARD_GetDriver()
43 #ifndef X_DISPLAY_MISSING
44 return &X11DRV_KEYBOARD_Driver;
45 #else /* X_DISPLAY_MISSING */
46 return &TTYDRV_KEYBOARD_Driver;
47 #endif /* X_DISPLAY_MISSING */
50 /***********************************************************************
51 * KEYBOARD_Inquire (KEYBOARD.1)
53 WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo)
55 kbInfo->Begin_First_Range = 0;
56 kbInfo->End_First_Range = 0;
57 kbInfo->Begin_Second_Range = 0;
58 kbInfo->End_Second_Range = 0;
59 kbInfo->StateSize = 16;
61 return sizeof(KBINFO);
64 /***********************************************************************
65 * KEYBOARD_Enable (KEYBOARD.2)
67 VOID WINAPI KEYBOARD_Enable( LPKEYBD_EVENT_PROC lpKeybEventProc,
68 LPBYTE lpKeyState )
70 static BOOL initDone = FALSE;
72 DefKeybEventProc = lpKeybEventProc;
73 pKeyStateTable = lpKeyState;
75 /* all states to false */
76 memset( lpKeyState, 0, sizeof(lpKeyState) );
78 if (!initDone) KEYBOARD_GetDriver()->pInit();
79 initDone = TRUE;
82 /***********************************************************************
83 * KEYBOARD_Disable (KEYBOARD.3)
85 VOID WINAPI KEYBOARD_Disable(VOID)
87 DefKeybEventProc = NULL;
88 pKeyStateTable = NULL;
91 /***********************************************************************
92 * KEYBOARD_SendEvent
94 void KEYBOARD_SendEvent( BYTE bVk, BYTE bScan, DWORD dwFlags,
95 DWORD posX, DWORD posY, DWORD time )
97 WINE_KEYBDEVENT wke;
99 if ( !DefKeybEventProc ) return;
101 TRACE( event, "(%d,%d,%04lX)\n", bVk, bScan, dwFlags );
103 wke.magic = WINE_KEYBDEVENT_MAGIC;
104 wke.posX = posX;
105 wke.posY = posY;
106 wke.time = time;
108 DefKeybEventProc( bVk, bScan, dwFlags, (DWORD)&wke );
111 /**********************************************************************
112 * ScreenSwitchEnable (KEYBOARD.100)
114 VOID WINAPI ScreenSwitchEnable16(WORD unused)
116 FIXME(keyboard,"(%04x): stub\n",unused);
119 /**********************************************************************
120 * OemKeyScan (KEYBOARD.128)(USER32.401)
122 DWORD WINAPI OemKeyScan(WORD wOemChar)
124 TRACE(keyboard,"*OemKeyScan (%d)\n",wOemChar);
126 return wOemChar;
129 /**********************************************************************
130 * VkKeyScan [KEYBOARD.129]
132 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
133 * for the current keyboard.
134 * high-order byte yields :
135 * 0 Unshifted
136 * 1 Shift
137 * 2 Ctrl
138 * 3-5 Shift-key combinations that are not used for characters
139 * 6 Ctrl-Alt
140 * 7 Ctrl-Alt-Shift
141 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
142 * FIXME : works ok except for dead chars :
143 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
144 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
147 WORD WINAPI VkKeyScan16(CHAR cChar)
149 return KEYBOARD_GetDriver()->pVkKeyScan(cChar);
152 /******************************************************************************
153 * GetKeyboardType16 (KEYBOARD.130)
155 INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
157 TRACE(keyboard,"(%d)\n",nTypeFlag);
158 switch(nTypeFlag)
160 case 0: /* Keyboard type */
161 return 4; /* AT-101 */
162 break;
163 case 1: /* Keyboard Subtype */
164 return 0; /* There are no defined subtypes */
165 break;
166 case 2: /* Number of F-keys */
167 return 12; /* We're doing an 101 for now, so return 12 F-keys */
168 break;
169 default:
170 WARN(keyboard, "Unknown type\n");
171 return 0; /* The book says 0 here, so 0 */
175 /******************************************************************************
176 * MapVirtualKey16 (KEYBOARD.131)
178 * MapVirtualKey translates keycodes from one format to another
180 UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
182 return KEYBOARD_GetDriver()->pMapVirtualKey(wCode,wMapType);
185 /****************************************************************************
186 * GetKBCodePage16 (KEYBOARD.132)
188 INT16 WINAPI GetKBCodePage16(void)
190 TRACE(keyboard,"(void)\n");
191 return 850;
194 /****************************************************************************
195 * GetKeyNameText16 (KEYBOARD.133)
197 INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
199 return KEYBOARD_GetDriver()->pGetKeyNameText(lParam, lpBuffer, nSize);
202 /****************************************************************************
203 * ToAscii (KEYBOARD.4)
205 * The ToAscii function translates the specified virtual-key code and keyboard
206 * state to the corresponding Windows character or characters.
208 * If the specified key is a dead key, the return value is negative. Otherwise,
209 * it is one of the following values:
210 * Value Meaning
211 * 0 The specified virtual key has no translation for the current state of the keyboard.
212 * 1 One Windows character was copied to the buffer.
213 * 2 Two characters were copied to the buffer. This usually happens when a
214 * dead-key character (accent or diacritic) stored in the keyboard layout cannot
215 * be composed with the specified virtual key to form a single character.
217 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
220 INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState,
221 LPVOID lpChar, UINT16 flags)
223 return KEYBOARD_GetDriver()->pToAscii(
224 virtKey, scanCode, lpKeyState, lpChar, flags