[vc++] как "нажать" shift+'a' c помощью WM_KEYDOWN

t332

подскажите, плиз, как сделать субж на VC++?
используя, например, вот это:
unsigned char KeyState[256];
GetKeyboardState(KeyState);
KeyState[0x10]=?;
SetKeyboardState(KeyState);
PostMessage(hwnd,WM_KEYDOWN,0x41,?);
PostMessage(hwnd,WM_KEYUP,0x41,?);
KeyState[0x10]=0;
SetKeyboardState(KeyState);

laki

А зачем именно так? мб лучше keybd_event

maggi14

А через WM_CHAR чем плохо?

t332

не то, чтобы обязательно так, но может кто заморачивался уже...
может кините сюда кусочек кода, с моей проблемой с использованием
WM_CHAR или keybd_event? плиз

maggi14

Я точно не помню, а подробно искать не буду.
Поищи про виртуальные клавиши.
Вот кусок из MSDN на эту (или смежную) тему:
GetKeyState Function
The GetKeyState function retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off—alternating each time the key is pressed).
Syntax
SHORT GetKeyState(
int nVirtKey
);
Parameters
nVirtKey
[in] Specifies a virtual key. If the desired virtual key is a letter or digit (A through Z, a through z, or 0 through 9 nVirtKey must be set to the ASCII value of that character. For other keys, it must be a virtual-key code.
If a non-English keyboard layout is used, virtual keys with values in the range ASCII A through Z and 0 through 9 are used to specify most of the character keys. For example, for the German keyboard layout, the virtual key of value ASCII O (0x4F) refers to the "o" key, whereas VK_OEM_1 refers to the "o with umlaut" key.
Return Value
The return value specifies the status of the specified virtual key, as follows:
If the high-order bit is 1, the key is down; otherwise, it is up.
If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.
Remarks
The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.
An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated.
To retrieve state information for all the virtual keys, use the GetKeyboardState function.
An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys.
VK_LSHIFT
VK_RSHIFT
VK_LCONTROL
VK_RCONTROL
VK_LMENU
VK_RMENU
These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
For an example, see Displaying Keyboard Input.
Function Information
Minimum DLL Version user32.dll
Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1
See Also
Keyboard Input, GetAsyncKeyState, GetKeyboardState, MapVirtualKey, SetKeyboardState

MapVirtualKey Function
The MapVirtualKey function translates (maps) a virtual-key code into a scan code or character value, or translates a scan code into a virtual-key code.
To specify a handle to the keyboard layout to use for translating the specified code, use the MapVirtualKeyEx function.
Syntax
UINT MapVirtualKey(
UINT uCode,
UINT uMapType
);
Parameters
uCode
[in] Specifies the virtual-key code or scan code for a key. How this value is interpreted depends on the value of the uMapType parameter.
uMapType
[in] Specifies the translation to perform. The value of this parameter depends on the value of the uCode parameter.
0
uCode is a virtual-key code and is translated into a scan code. If it is a virtual-key code that does not distinguish between left- and right-hand keys, the left-hand scan code is returned. If there is no translation, the function returns 0.
1
uCode is a scan code and is translated into a virtual-key code that does not distinguish between left- and right-hand keys. If there is no translation, the function returns 0.
2
uCode is a virtual-key code and is translated into an unshifted character value in the low-order word of the return value. Dead keys (diacritics) are indicated by setting the top bit of the return value. If there is no translation, the function returns 0.
3
Windows NT/2000/XP: uCode is a scan code and is translated into a virtual-key code that distinguishes between left- and right-hand keys. If there is no translation, the function returns 0.
Return Value
The return value is either a scan code, a virtual-key code, or a character value, depending on the value of uCode and uMapType. If there is no translation, the return value is zero.
Remarks
An application can use MapVirtualKey to translate scan codes to the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU, and vice versa. These translations do not distinguish between the left and right instances of the SHIFT, CTRL, or ALT keys.
Windows NT/2000/XP: An application can get the scan code corresponding to the left or right instance of one of these keys by calling MapVirtualKey with uCode set to one of the following virtual-key code constants.
VK_LSHIFT
VK_RSHIFT
VK_LCONTROL
VK_RCONTROL
VK_LMENU
VK_RMENU
These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
Windows 95/98/Me: MapVirtualKeyW is supported by the Microsoft® Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
Function Information
Minimum DLL Version user32.dll
Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP
See Also
Keyboard Input, GetAsyncKeyState, GetKeyboardState, GetKeyState, MapVirtualKeyEx, SetKeyboardState

t332

я все это читал, но все равно не получается... хелп!
up!

Morayn

up!

major

changing...

lenabarskaya

Что значит "нажать"?
Хочешь, чтобы какое-то конкретное приложение совершило нечто, что в нём "подвешено" к этой комбинации? Или сэмулировать нажатие её пользователем на клавиатуре, безотносительно какого-либо контекста? Ещё что-то?
Опиши точно, что тебе надо.

t332

хочу програмно (сэмулировать) нажать 'A' (именно прописную)
... для маленьких букв работает PostMessage(hwnd,WM_KEYDOWN,Key,0);
а нужно "нажимать" и большие буквы тоже!
именно с помощью PostMessage(hwnd,WM_KEYDOWN,?,? так как окно (hwnd) может быть
не активным. MSDN мне не помог, вернее я так и не смог разобраться с последним параметром
в PostMessage, который вроде бы как (для WM_KEYDOWN) и отвечает за SHIFT и прочее...
хелп!

lenabarskaya

так как окно (hwnd)

Какое окно? "Какой заяц?! Какая блоха?!" (с)
Если хочешь получить ответ на свой вопрос - потрудись задать его аккуратно. Лучше, если ты не будешь продолжать ебать присутствующим мозг, а просто опишешь конкретную задачу, которую пытаешься решать.

Bird_V

А в чём проблема? Напиши прогу, которая выводит на экран оба параметра
сообщения WM_CHAR, запомни, и потом вставь куда надо.
Моя клава выдаёт следующие параметры: wparam=97, lparam=1966081.
Вставь следующий код


case WM_CHAR:
char text[256];
sprintf(text, "WM_KEYDOWN triggered, wparam=%u, lparam=%ld", wParam, lParam);
MessageBox(hWnd, text, "WM_KEYDOWN", MB_OK);
break;


в WndProc (не забудь stdio.h подключить для sprintf).
Если нужен полный код - скажи, куда кинуть.

t332

кинь плиз в
и еще... а WM_KEYDOWN и WM_CHAR - одно и тоже?

Bird_V

кинул "получалку кодов для WM_CHAR". WM_CHAR и WM_KEYDOWN не одно и то-же,
WM_CHAR не ловит клавиши shift, ctrl, alt(?).

t332

кинь пожалуйста еще exe-шник (release а то у меня VC++ 6 - не хочется ставить новый VC++ ...
по крайней мере - не сейчас 8)

maggi14

Воспользуйся MS Spy++

Bird_V

А что, создать пустой проект Win32 Application и добавить в него мой
cpp-фалй нельзя?
Оставить комментарий
Имя или ник:
Комментарий: