I am trying to print the corresponding Unicode character for alt+2 to the Windows console window. (the console doesn't display the character, but should display ^B instead)
The following doesn't seem to work. Just prints "2".

keybd_event(VK_MENU,0 ,0 , 0); //Alt Press

Sleep(10);
keybd_event(VK_NUMPAD2,0, 0 , 0); // 2 Press

Sleep(10);
keybd_event(VK_NUMPAD2,0, KEYEVENTF_KEYUP,0); // 2 Release

Sleep(10);
keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0); // Alt Release

Sleep(10);

Neither does this work. Again, just prints "2".

INPUT inputs = {0}; 
inputs.type = INPUT_KEYBOARD; 

KEYBDINPUT ki = {0}; 
ki.wVk = VK_LMENU;

inputs.ki = ki;
SendInput(1, &inputs, sizeof(INPUT)); // Left alt

ki.wVk = VK_NUMPAD2;
inputs.ki = ki;
SendInput(1, &inputs, sizeof(INPUT)); // Numpad 2

ki.dwFlags = KEYEVENTF_KEYUP;

ki.wVk = VK_NUMPAD2;
inputs.ki = ki;
SendInput(1, &inputs, sizeof(INPUT)); // Numpad 2

ki.wVk = VK_LMENU;
inputs.ki = ki;
SendInput(1, &inputs, sizeof(INPUT)); // Left alt

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I did some experimenting after running the console window on my computer (Windows Vista SP 2) and I produced ^B with ctrl + b keys pressed.

No, you don't get what I need to do. I want to display ^B with alt+2 combination. The combination is supposed to produce this character ☻, but the console doesn't diplay it so. Later I'm planning to send the simulated combination to active window, but I'm starting off with the basic - producing output from the combination to a console window.

This article has been dead for over six months. Start a new discussion instead.