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

2020-07-10 10: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条回答
爷的心禁止访问
2楼-- · 2020-07-10 11:01

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!

查看更多
登录 后发表回答