Sending Two or more chars using SendInput

前端 未结 2 1806
终归单人心
终归单人心 2020-12-03 20:26

To send a char, we can use SendInput. How can I use it to send more than one char?

I tried this code but it does not send anything:

INPUT in;
in.type         


        
2条回答
  •  Happy的楠姐
    2020-12-03 20:53

    If I've got you right, you want something more along the lines of this:

    INPUT in[4] = {0}; // four inputs
    
    // first input 0x53
    in[0].type=INPUT_KEYBOARD;
    in[0].ki.wScan=0;
    in[0].ki.dwFlags=0;
    in[0].ki.time=0;
    in[0].ki.dwExtraInfo=0;
    in[0].ki.wVk=0x53;
    
    in[1] = in[0];
    in[1].ki.dwFlags |= KEYEVENTF_KEYUP;
    
    // second input 0x54
    in[2].type=INPUT_KEYBOARD;
    in[2].ki.wScan=0;
    in[2].ki.dwFlags=0;
    in[2].ki.time=0;
    in[2].ki.dwExtraInfo=0;
    in[2].ki.wVk=0x54;
    
    in[3] = in[2];
    in[3].ki.dwFlags |= KEYEVENTF_KEYUP;
    
    SendInput(4,in,sizeof(INPUT));
    

    Probably want to wrap the grunt work setting up the INPUT structure into a function to reduce duplication.

提交回复
热议问题