Fix return type of GetAsyncKeyState.
[wine] / windows / keyboard.c
1 /*
2  * KEYBOARD driver
3  *
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
9  *
10  */
11
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
15
16 #include "windef.h"
17 #include "winbase.h"
18 #include "wingdi.h"
19 #include "winuser.h"
20 #include "win.h"
21 #include "user.h"
22 #include "message.h"
23 #include "debugtools.h"
24 #include "winerror.h"
25
26 DEFAULT_DEBUG_CHANNEL(keyboard);
27
28 #include "pshpack1.h"
29 typedef struct _KBINFO
30 {
31     BYTE Begin_First_Range;
32     BYTE End_First_Range;
33     BYTE Begin_Second_Range;
34     BYTE End_Second_Range;
35     WORD StateSize;
36 } KBINFO, *LPKBINFO;
37 #include "poppack.h"
38
39 static FARPROC16 DefKeybEventProc;
40 static LPBYTE pKeyStateTable;
41
42 /***********************************************************************
43  *              Inquire (KEYBOARD.1)
44  */
45 WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo) 
46 {
47   kbInfo->Begin_First_Range = 0;
48   kbInfo->End_First_Range = 0;
49   kbInfo->Begin_Second_Range = 0;
50   kbInfo->End_Second_Range = 0;
51   kbInfo->StateSize = 16; 
52   
53   return sizeof(KBINFO);
54 }
55
56 /***********************************************************************
57  *              Enable (KEYBOARD.2)
58  */
59 VOID WINAPI KEYBOARD_Enable( FARPROC16 proc, LPBYTE lpKeyState )
60 {
61     DefKeybEventProc = proc;
62     pKeyStateTable = lpKeyState;
63
64     memset( lpKeyState, 0, 256 ); /* all states to false */
65 }
66
67 /***********************************************************************
68  *              Disable (KEYBOARD.3)
69  */
70 VOID WINAPI KEYBOARD_Disable(VOID)
71 {
72     DefKeybEventProc = NULL;
73     pKeyStateTable = NULL;
74 }
75
76
77 /**********************************************************************
78  *              SetSpeed (KEYBOARD.7)
79  */
80 WORD WINAPI SetSpeed16(WORD unused)
81 {
82     FIXME("(%04x): stub\n", unused);
83     return 0xffff;
84 }
85
86 /**********************************************************************
87  *              ScreenSwitchEnable (KEYBOARD.100)
88  */
89 VOID WINAPI ScreenSwitchEnable16(WORD unused)
90 {
91   FIXME("(%04x): stub\n", unused);
92 }
93
94 /**********************************************************************
95  *              OemKeyScan (KEYBOARD.128)
96  *              OemKeyScan (USER32.@)
97  */
98 DWORD WINAPI OemKeyScan(WORD wOemChar)
99 {
100   TRACE("(%d)\n", wOemChar);
101
102   return wOemChar;
103 }
104
105 /**********************************************************************
106  *              VkKeyScan (KEYBOARD.129)
107  */
108 WORD WINAPI VkKeyScan16(CHAR cChar)
109 {
110     return VkKeyScanA( cChar );
111 }
112
113 /******************************************************************************
114  *              GetKeyboardType (KEYBOARD.130)
115  */
116 INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
117 {
118     return GetKeyboardType( nTypeFlag );
119 }
120
121 /******************************************************************************
122  *              MapVirtualKey (KEYBOARD.131)
123  *
124  * MapVirtualKey translates keycodes from one format to another
125  */
126 UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
127 {
128     return MapVirtualKeyA(wCode,wMapType);
129 }
130
131 /****************************************************************************
132  *              GetKBCodePage (KEYBOARD.132)
133  */
134 INT16 WINAPI GetKBCodePage16(void)
135 {
136     return GetKBCodePage();
137 }
138
139 /****************************************************************************
140  *              GetKeyNameText (KEYBOARD.133)
141  */
142 INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
143 {
144     return GetKeyNameTextA( lParam, lpBuffer, nSize );
145 }
146
147 /****************************************************************************
148  *              ToAscii (KEYBOARD.4)
149  *
150  * The ToAscii function translates the specified virtual-key code and keyboard
151  * state to the corresponding Windows character or characters.
152  *
153  * If the specified key is a dead key, the return value is negative. Otherwise,
154  * it is one of the following values:
155  * Value        Meaning
156  * 0    The specified virtual key has no translation for the current state of the keyboard.
157  * 1    One Windows character was copied to the buffer.
158  * 2    Two characters were copied to the buffer. This usually happens when a
159  *      dead-key character (accent or diacritic) stored in the keyboard layout cannot
160  *      be composed with the specified virtual key to form a single character.
161  *
162  * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
163  *
164  */
165 INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState, 
166                        LPVOID lpChar, UINT16 flags) 
167 {
168     return ToAscii( virtKey, scanCode, lpKeyState, lpChar, flags );
169 }
170
171 /***********************************************************************
172  *              MessageBeep (USER.104)
173  */
174 void WINAPI MessageBeep16( UINT16 i )
175 {
176     MessageBeep( i );
177 }
178
179 /***********************************************************************
180  *              MessageBeep (USER32.@)
181  */
182 BOOL WINAPI MessageBeep( UINT i )
183 {
184     BOOL active = TRUE;
185     SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
186     if (active) USER_Driver.pBeep();
187     return TRUE;
188 }