S
S
Sergo Zar2019-11-24 16:00:12
C++ / C#
Sergo Zar, 2019-11-24 16:00:12

How to simulate left click in c++?

Please tell me how to simulate pressing LMB.
When I specify 'VK_TAB' or 'keyboard symbol' everything works, but when I enter VK_LBUTTON nothing happens. Why is that?
After all, if I had written the wrong button name, the program would not have compiled at all.
Here is the code:

#include <iostream>
#include <Windows.h>
#pragma comment(lib,"user32")
using namespace std;



int main()
{
    string txt;

    for(int i=0;i <100;i++ ){
        keybd_event (VK_LBUTTON,0,0,0);
  
        cout << i <<endl;
        Sleep(100);
    }
    
    return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2021-09-20
@Sergomen

> After all, if I wrote the wrong name of the button, then the program would not be compiled at all.
But no, it will still compile, since these enums are numbers in int.
keybd_event for keyboard and mouse_event for mice

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question