simulating alt+2 (keypad) combination

This is a discussion on simulating alt+2 (keypad) combination within the C++ Programming forums, part of the General Programming Boards category; I am trying to print the corresponding Unicode character for alt+2 to the Windows console window. (the console doesn't display ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    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

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    The character is Ctrl+B. So you would want to simulate a keypress of CTRL and B at the same time.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    2
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alt key help
    By munna_dude in forum C Programming
    Replies: 5
    Last Post: 10-08-2007, 01:51 AM
  2. Disable ALT key commands
    By Lionmane in forum Windows Programming
    Replies: 9
    Last Post: 09-23-2005, 11:41 AM
  3. code for Alt + Tab keys
    By Sumir in forum Windows Programming
    Replies: 2
    Last Post: 10-12-2002, 04:49 AM
  4. Thanks Stoned_Coder! ALT key works!!
    By johnnyd in forum C Programming
    Replies: 0
    Last Post: 03-11-2002, 10:39 AM
  5. Capturing ALT in C
    By johnnyd in forum C Programming
    Replies: 2
    Last Post: 03-10-2002, 10:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21