none
Virtual keyboard CTRL+A RRS feed

  • Question

  • I am using visual C# and trying to make automation press CTRL+A button combination.

    I am using this code:

    keybd_event(A, 0, KEYEVENTF_EXTENDEDKEY, 0);
        Task.Delay(TimeSpan.FromMilliseconds(100)).Wait();
        keybd_event(ctrl, 0, KEYEVENTF_KEYUP, 0);
        keybd_event(A, 0, KEYEVENTF_KEYUP, 0);

    variables

    public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag
    public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag
    public const int A = 0x41; //A key code
    public const int ctrl = 0xA2; //ctrl key code
    But when program executed code it all time leave pressed CTRL button. I don't know why don't release it. If I press and release right CTRL button in my keyboard. When it release. Maybe know how solve this problem?
    Tuesday, July 31, 2018 8:17 PM

All replies

  • There is no Ctrl down (0) in your sample.

    =>

    keybd_event(VK_LCONTROL, 0, KEYEVENTF_EXTENDEDKEY, 0);
    keybd_event((byte)Keys.A, 0, 0, 0);
    keybd_event((byte)Keys.A, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_LCONTROL, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);

    Tuesday, July 31, 2018 9:01 PM
  • Hi pcwortex,

    The following document also provide a sample about CTRL+A

    // Simulating a Ctrl+A keystroke
    keybd_event(VK_CONTROL,0x9d,0 , 0); // Ctrl Press
    keybd_event(VkKeyScan('A'),0x9e,0 , 0); // ‘A’ Press
    keybd_event(VkKeyScan('A'),0x9e, KEYEVENTF_KEYUP,0); // ‘A’ Release
    keybd_event(VK_CONTROL,0x9d,KEYEVENTF_KEYUP,0); // Ctrl Release

    https://www.codeproject.com/Articles/7305/Keyboard-Events-Simulation-using-keybd-event-funct

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 1, 2018 5:14 AM
    Moderator
  • Thank, It is  working now well
    Wednesday, August 1, 2018 12:14 PM
  • Thank for your help. I solved problem
    Wednesday, August 1, 2018 12:14 PM
  • Hi pcwortex,

    I am glad to know that you resolve the issue, please mark the helpful reply as answer, it will be beneficial to other communities who have the similar issue.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 3, 2018 1:20 AM
    Moderator