1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

simulating alt+2 (keypad) combination

Discussion in 'C' started by kangekraam, Nov 20, 2009.

  1. kangekraam

    kangekraam New Member

    Joined:
    Nov 20, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     

Share This Page