Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 898
Kaije Avatar asked Sep 16 '10 12:09

Kaije


1 Answers

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!

like image 137
wmeyer Avatar answered Nov 09 '22 21:11

wmeyer