kbd16.c 6.65 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
2
 * KEYBOARD driver
Alexandre Julliard's avatar
Alexandre Julliard committed
3 4
 *
 * Copyright 1993 Bob Amstadt
5
 * Copyright 1996 Albrecht Kleine
Alexandre Julliard's avatar
Alexandre Julliard committed
6
 * Copyright 1997 David Faure
Alexandre Julliard's avatar
Alexandre Julliard committed
7
 * Copyright 1998 Morten Welinder
8
 * Copyright 1998 Ulrich Weigand
Alexandre Julliard's avatar
Alexandre Julliard committed
9
 *
10 11 12 13 14 15 16 17 18 19 20 21
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard's avatar
Alexandre Julliard committed
23
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
24

25
#include <stdarg.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
26
#include <stdlib.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
27
#include <string.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
28
#include <ctype.h>
29

30
#include "windef.h"
31
#include "winbase.h"
32
#include "wingdi.h"
33
#include "winuser.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
34
#include "winerror.h"
35 36
#include "wine/winuser16.h"
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
37

38
WINE_DEFAULT_DEBUG_CHANNEL(keyboard);
39 40 41 42 43 44 45 46 47 48 49

#include "pshpack1.h"
typedef struct _KBINFO
{
    BYTE Begin_First_Range;
    BYTE End_First_Range;
    BYTE Begin_Second_Range;
    BYTE End_Second_Range;
    WORD StateSize;
} KBINFO, *LPKBINFO;
#include "poppack.h"
50

51
static FARPROC16 DefKeybEventProc;
52
static LPBYTE pKeyStateTable;
53

54 55 56
/***********************************************************************
 *		Inquire (KEYBOARD.1)
 */
57
WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo)
58 59 60 61 62
{
  kbInfo->Begin_First_Range = 0;
  kbInfo->End_First_Range = 0;
  kbInfo->Begin_Second_Range = 0;
  kbInfo->End_Second_Range = 0;
63 64
  kbInfo->StateSize = 16;

65 66
  return sizeof(KBINFO);
}
67

68 69 70 71
/***********************************************************************
 *		Enable (KEYBOARD.2)
 */
VOID WINAPI KEYBOARD_Enable( FARPROC16 proc, LPBYTE lpKeyState )
72
{
73
    DefKeybEventProc = proc;
74
    pKeyStateTable = lpKeyState;
75

76
    memset( lpKeyState, 0, 256 ); /* all states to false */
77 78
}

79
/***********************************************************************
80
 *		Disable (KEYBOARD.3)
81 82 83
 */
VOID WINAPI KEYBOARD_Disable(VOID)
{
84 85
    DefKeybEventProc = NULL;
    pKeyStateTable = NULL;
86 87
}

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
/***********************************************************************
 *           AnsiToOem   (KEYBOARD.5)
 */
INT16 WINAPI AnsiToOem16( LPCSTR s, LPSTR d )
{
    CharToOemA( s, d );
    return -1;
}

/***********************************************************************
 *           OemToAnsi   (KEYBOARD.6)
 */
INT16 WINAPI OemToAnsi16( LPCSTR s, LPSTR d )
{
    OemToCharA( s, d );
    return -1;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
105

106
/**********************************************************************
107
 *		SetSpeed (KEYBOARD.7)
108 109 110
 */
WORD WINAPI SetSpeed16(WORD unused)
{
111
    FIXME("(%04x): stub\n", unused);
112 113 114
    return 0xffff;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
115
/**********************************************************************
116
 *		ScreenSwitchEnable (KEYBOARD.100)
Alexandre Julliard's avatar
Alexandre Julliard committed
117
 */
118
VOID WINAPI ScreenSwitchEnable16(WORD unused)
Alexandre Julliard's avatar
Alexandre Julliard committed
119
{
120
  FIXME("(%04x): stub\n", unused);
Alexandre Julliard's avatar
Alexandre Julliard committed
121 122
}

Alexandre Julliard's avatar
Alexandre Julliard committed
123
/**********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
124
 *		OemKeyScan (KEYBOARD.128)
Alexandre Julliard's avatar
Alexandre Julliard committed
125
 */
126
DWORD WINAPI OemKeyScan16(WORD wOemChar)
Alexandre Julliard's avatar
Alexandre Julliard committed
127
{
128
    return OemKeyScan( wOemChar );
Alexandre Julliard's avatar
Alexandre Julliard committed
129 130
}

Alexandre Julliard's avatar
Alexandre Julliard committed
131
/**********************************************************************
132
 *		VkKeyScan (KEYBOARD.129)
Alexandre Julliard's avatar
Alexandre Julliard committed
133
 */
134
WORD WINAPI VkKeyScan16(CHAR cChar)
Alexandre Julliard's avatar
Alexandre Julliard committed
135
{
136
    return VkKeyScanA( cChar );
Alexandre Julliard's avatar
Alexandre Julliard committed
137 138
}

Alexandre Julliard's avatar
Alexandre Julliard committed
139
/******************************************************************************
140
 *		GetKeyboardType (KEYBOARD.130)
Alexandre Julliard's avatar
Alexandre Julliard committed
141
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
142
INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
Alexandre Julliard's avatar
Alexandre Julliard committed
143
{
144
    return GetKeyboardType( nTypeFlag );
Alexandre Julliard's avatar
Alexandre Julliard committed
145 146
}

Alexandre Julliard's avatar
Alexandre Julliard committed
147
/******************************************************************************
148
 *		MapVirtualKey (KEYBOARD.131)
Alexandre Julliard's avatar
Alexandre Julliard committed
149
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
150 151
 * MapVirtualKey translates keycodes from one format to another
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
152
UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
Alexandre Julliard's avatar
Alexandre Julliard committed
153
{
154
    return MapVirtualKeyA(wCode,wMapType);
Alexandre Julliard's avatar
Alexandre Julliard committed
155 156
}

Alexandre Julliard's avatar
Alexandre Julliard committed
157
/****************************************************************************
158
 *		GetKBCodePage (KEYBOARD.132)
Alexandre Julliard's avatar
Alexandre Julliard committed
159
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
160
INT16 WINAPI GetKBCodePage16(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
161
{
162
    return GetKBCodePage();
Alexandre Julliard's avatar
Alexandre Julliard committed
163 164
}

Alexandre Julliard's avatar
Alexandre Julliard committed
165
/****************************************************************************
166
 *		GetKeyNameText (KEYBOARD.133)
Alexandre Julliard's avatar
Alexandre Julliard committed
167
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
168
INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
Alexandre Julliard's avatar
Alexandre Julliard committed
169
{
170
    return GetKeyNameTextA( lParam, lpBuffer, nSize );
Alexandre Julliard's avatar
Alexandre Julliard committed
171 172
}

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
/***********************************************************************
 *           AnsiToOemBuff   (KEYBOARD.134)
 */
void WINAPI AnsiToOemBuff16( LPCSTR s, LPSTR d, UINT16 len )
{
    if (len != 0) CharToOemBuffA( s, d, len );
}

/***********************************************************************
 *           OemToAnsiBuff   (KEYBOARD.135)
 */
void WINAPI OemToAnsiBuff16( LPCSTR s, LPSTR d, UINT16 len )
{
    if (len != 0) OemToCharBuffA( s, d, len );
}

Alexandre Julliard's avatar
Alexandre Julliard committed
189
/****************************************************************************
190
 *		ToAscii (KEYBOARD.4)
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
 *
 * The ToAscii function translates the specified virtual-key code and keyboard
 * state to the corresponding Windows character or characters.
 *
 * If the specified key is a dead key, the return value is negative. Otherwise,
 * it is one of the following values:
 * Value	Meaning
 * 0	The specified virtual key has no translation for the current state of the keyboard.
 * 1	One Windows character was copied to the buffer.
 * 2	Two characters were copied to the buffer. This usually happens when a
 *      dead-key character (accent or diacritic) stored in the keyboard layout cannot
 *      be composed with the specified virtual key to form a single character.
 *
 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
206
 */
207 208
INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState,
                       LPVOID lpChar, UINT16 flags)
Alexandre Julliard's avatar
Alexandre Julliard committed
209
{
210
    return ToAscii( virtKey, scanCode, lpKeyState, lpChar, flags );
Alexandre Julliard's avatar
Alexandre Julliard committed
211
}
212

213
/***********************************************************************
214
 *		MessageBeep (USER.104)
215
 */
216
void WINAPI MessageBeep16( UINT16 i )
217
{
218
    MessageBeep( i );
219
}
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242

/***********************************************************************
 *		keybd_event (USER.289)
 */
void WINAPI keybd_event16( CONTEXT86 *context )
{
    DWORD dwFlags = 0;

    if (HIBYTE(context->Eax) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
    if (HIBYTE(context->Ebx) & 0x01) dwFlags |= KEYEVENTF_EXTENDEDKEY;

    keybd_event( LOBYTE(context->Eax), LOBYTE(context->Ebx),
                 dwFlags, MAKELONG(LOWORD(context->Esi), LOWORD(context->Edi)) );
}


/****************************************************************************
 *		GetKeyboardLayoutName (USER.477)
 */
INT16 WINAPI GetKeyboardLayoutName16( LPSTR name )
{
    return GetKeyboardLayoutNameA( name );
}