0

Working on an application that uses RDP ActiveX controls. Trying to use IMsRdpClientNonScriptable::SendKeys to simulate Win + L combo to Lock the screen within RDP session, but its not working. Only L key seems to go through?

    long nKeyCount = 4;
    VARIANT_BOOL keyUp[4];
    long keyData[4];        

    keyData[0] = 92;
    keyData[1] = SC_L;
    keyData[2] = SC_L;
    keyData[3] = 92;


    keyUp[0] = VARIANT_FALSE;
    keyUp[1] = VARIANT_FALSE;
    keyUp[2] = VARIANT_TRUE;
    keyUp[3] = VARIANT_TRUE;

    rdpclient.SendKeys(nKeyCount, &keyUp[0], &keyData[0]);

Edit: Tried assigning values using LPARAM format. This didn't work either.

    keyData[0] = WmKeyDown_lParam(92, 0, 1);
    keyData[1] = WmKeyDown_lParam(SC_L, 0, 1);
    keyData[2] = WmKeyDown_lParam(SC_L, 1, 1);
    keyData[3] = WmKeyDown_lParam(92, 1, 1);

    long Rdp::WmKeyDown_lParam(uint scanCode, uint prevState, uint extended)
    {
        //scan does works
        uint repeatCount = 0;        
        uint context = 0;
        uint previousState = prevState;
        uint transition = 0;

        // combine the parameters above according to the bit
        // fields described in the MSDN page for WM_KEYDOWN

        long lParam = repeatCount
            | (scanCode << 16)
            | (extended << 24)
            | (context << 29)
            | (previousState << 30)
            | (transition << 31);

        //lParam = scanCode << 16;
        return lParam;
     }
tunafish24
  • 2,288
  • 6
  • 28
  • 47
  • The scan code is encoded in bits 16..23. And it is an extended key. And it was previously down when you release the key. – Hans Passant Jan 07 '20 at 09:41
  • @HansPassant Actually I had tried using WPARAM earlier as well, but that didn't work either. Is there something wrong with the code? I did check bits as per msdn documentation and they seemed fine to me. – tunafish24 Jan 07 '20 at 10:35
  • The L key is not an extended key. 91 is another scancode to try (left vs right). – Hans Passant Jan 07 '20 at 10:41
  • Fixed the extended flag and used 91 scancode, still didn't work. Interestingly, when I use scancode directly e.g. keyData[1] = SC_L; then remote desktop with notepad open did show "l" being typed, but it doesn't with LPARAM format. – tunafish24 Jan 07 '20 at 10:48
  • Do keep in mind that you might be battling a CVE-2019-9510 patch, disconnecting instead of locking is the better way. – Hans Passant Jan 07 '20 at 10:48

0 Answers0