Fixed bug in CreateFileMapping when name is not NULL.
[wine/multimedia.git] / windows / keyboard.c
blob85ea3b88123717478dd7a70c93f43d4c3a1b9b3b
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 <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
15 #include "windows.h"
16 #include "win.h"
17 #include "gdi.h"
18 #include "heap.h"
19 #include "keyboard.h"
20 #include "message.h"
21 #include "debug.h"
22 #include "debugtools.h"
23 #include "struct32.h"
24 #include "winerror.h"
26 static LPKEYBD_EVENT_PROC DefKeybEventProc = NULL;
27 LPBYTE pKeyStateTable = NULL;
29 extern KEYBOARD_DRIVER X11DRV_KEYBOARD_Driver;
31 /***********************************************************************
32 * KEYBOARD_GetDriver
34 KEYBOARD_DRIVER *KEYBOARD_GetDriver()
36 return &X11DRV_KEYBOARD_Driver;
39 /***********************************************************************
40 * KEYBOARD_Inquire (KEYBOARD.1)
42 WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo)
44 kbInfo->Begin_First_Range = 0;
45 kbInfo->End_First_Range = 0;
46 kbInfo->Begin_Second_Range = 0;
47 kbInfo->End_Second_Range = 0;
48 kbInfo->StateSize = 16;
50 return sizeof(KBINFO);
53 /***********************************************************************
54 * KEYBOARD_Enable (KEYBOARD.2)
56 VOID WINAPI KEYBOARD_Enable( LPKEYBD_EVENT_PROC lpKeybEventProc,
57 LPBYTE lpKeyState )
59 static BOOL32 initDone = FALSE;
61 DefKeybEventProc = lpKeybEventProc;
62 pKeyStateTable = lpKeyState;
64 /* all states to false */
65 memset( lpKeyState, 0, sizeof(lpKeyState) );
67 if (!initDone) KEYBOARD_GetDriver()->pInit();
68 initDone = TRUE;
71 /***********************************************************************
72 * KEYBOARD_Disable (KEYBOARD.3)
74 VOID WINAPI KEYBOARD_Disable(VOID)
76 DefKeybEventProc = NULL;
77 pKeyStateTable = NULL;
80 /***********************************************************************
81 * KEYBOARD_SendEvent
83 void KEYBOARD_SendEvent( BYTE bVk, BYTE bScan, DWORD dwFlags,
84 DWORD posX, DWORD posY, DWORD time )
86 WINE_KEYBDEVENT wke;
88 if ( !DefKeybEventProc ) return;
90 TRACE( event, "(%d,%d,%04lX)\n", bVk, bScan, dwFlags );
92 wke.magic = WINE_KEYBDEVENT_MAGIC;
93 wke.posX = posX;
94 wke.posY = posY;
95 wke.time = time;
97 DefKeybEventProc( bVk, bScan, dwFlags, (DWORD)&wke );
100 /**********************************************************************
101 * ScreenSwitchEnable (KEYBOARD.100)
103 VOID WINAPI ScreenSwitchEnable(WORD unused)
105 FIXME(keyboard,"(%04x): stub\n",unused);
108 /**********************************************************************
109 * OemKeyScan (KEYBOARD.128)(USER32.401)
111 DWORD WINAPI OemKeyScan(WORD wOemChar)
113 TRACE(keyboard,"*OemKeyScan (%d)\n",wOemChar);
115 return wOemChar;
118 /**********************************************************************
119 * VkKeyScan [KEYBOARD.129]
121 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
122 * for the current keyboard.
123 * high-order byte yields :
124 * 0 Unshifted
125 * 1 Shift
126 * 2 Ctrl
127 * 3-5 Shift-key combinations that are not used for characters
128 * 6 Ctrl-Alt
129 * 7 Ctrl-Alt-Shift
130 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
131 * FIXME : works ok except for dead chars :
132 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
133 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
136 WORD WINAPI VkKeyScan16(CHAR cChar)
138 return KEYBOARD_GetDriver()->pVkKeyScan(cChar);
141 /******************************************************************************
142 * GetKeyboardType16 (KEYBOARD.130)
144 INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
146 TRACE(keyboard,"(%d)\n",nTypeFlag);
147 switch(nTypeFlag)
149 case 0: /* Keyboard type */
150 return 4; /* AT-101 */
151 break;
152 case 1: /* Keyboard Subtype */
153 return 0; /* There are no defined subtypes */
154 break;
155 case 2: /* Number of F-keys */
156 return 12; /* We're doing an 101 for now, so return 12 F-keys */
157 break;
158 default:
159 WARN(keyboard, "Unknown type\n");
160 return 0; /* The book says 0 here, so 0 */
164 /******************************************************************************
165 * MapVirtualKey16 (KEYBOARD.131)
167 * MapVirtualKey translates keycodes from one format to another
169 UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
171 return KEYBOARD_GetDriver()->pMapVirtualKey(wCode,wMapType);
174 /****************************************************************************
175 * GetKBCodePage16 (KEYBOARD.132)
177 INT16 WINAPI GetKBCodePage16(void)
179 TRACE(keyboard,"(void)\n");
180 return 850;
183 /****************************************************************************
184 * GetKeyNameText16 (KEYBOARD.133)
186 INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
188 return KEYBOARD_GetDriver()->pGetKeyNameText(lParam, lpBuffer, nSize);
191 /****************************************************************************
192 * ToAscii (KEYBOARD.4)
194 * The ToAscii function translates the specified virtual-key code and keyboard
195 * state to the corresponding Windows character or characters.
197 * If the specified key is a dead key, the return value is negative. Otherwise,
198 * it is one of the following values:
199 * Value Meaning
200 * 0 The specified virtual key has no translation for the current state of the keyboard.
201 * 1 One Windows character was copied to the buffer.
202 * 2 Two characters were copied to the buffer. This usually happens when a
203 * dead-key character (accent or diacritic) stored in the keyboard layout cannot
204 * be composed with the specified virtual key to form a single character.
206 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
209 INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState,
210 LPVOID lpChar, UINT16 flags)
212 return KEYBOARD_GetDriver()->pToAscii(
213 virtKey, scanCode, lpKeyState, lpChar, flags