How to send unicode keys with c++ (keybd_event)

喜夏-厌秋 提交于 2019-12-06 01:40:06

问题


My friend is learning Norwegian and i want to make a global hot key program which sends keys such as

æ
ø
å

My problem is that keybd_event function wont allow me to send those keys, i seem to be restricted to the virtual key codes is there another function that i could use or some trick to sending them?


回答1:


You have to use SendInput instead. keybd_event does not support sending such characters (except if they are already in the current codepage, like on Norwegian computers). A bit of sample code to send an å:

KEYBDINPUT kb={0};
INPUT Input={0};

// down
kb.wScan = 0x00c5;
kb.dwFlags = KEYEVENTF_UNICODE;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));

// up
kb.wScan = 0x00c5;
kb.dwFlags = KEYEVENTF_UNICODE|KEYEVENTF_KEYUP;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));

In case you didn't know: it is easy to install additional keyboard layouts on Windows and switch between them with a shortcut.

Lykke til!



来源:https://stackoverflow.com/questions/3726812/how-to-send-unicode-keys-with-c-keybd-event

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!