Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   simulating alt+2 (keypad) combination (http://www.go4expert.com/forums/simulating-alt2-keypad-combination-t20152/)

kangekraam 21Nov2009 02:26

simulating alt+2 (keypad) combination
 
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".

Code:

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. Just prints "2", again.
Code:

    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



All times are GMT +5.5. The time now is 00:15.