i'm new here and new in any other than C, too litle in C# and none of C++ I heard about C not being capable of multithreading, because it's read line by line, POSIX and stuff, but what i want is to run two input functions from C at the same time. Does not matter if I have to pick up a lot of libraries from C to C++ or whatever.
I was trying to execute this simple code below:
#include<stdio.h>
#include<windows.h>
#include<conio.h>
// Display message until key is pressed.
// This structure will be used to create the keyboard and mouse
// input event
int main () {
int x=1;
INPUT ip,ip2,ip3;
ip.type = 0;
ip.mi.mouseData = XBUTTON1;
ip.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
ip.mi.time = 0;
ip2.type= 0;
ip2.mi.mouseData=XBUTTON1;
ip2.mi.dwFlags=MOUSEEVENTF_LEFTUP;
ip2.mi.time = 0;
ip3.type= INPUT_KEYBOARD;
ip3.ki.wVk= VK_RETURN;
ip3.ki.dwFlags=0;
ip3.ki.time=0;
while(x=1){
Sleep(5000);
SendInput(1,&ip3,sizeof(ip3));
SendInput(1,&ip,sizeof(ip));
SendInput(1,&ip2,sizeof(ip2));
}
}
What i really want is to synthesize a keyboard stroke enter and a left click press to be readed by my desktop at exactly same time. Does not necessary need to be this function at all. How do I make this run at the SAME TIME? could you guys gimme a refreshed version of this simple code that could achieve that?
That's just nonsense - C was probably the first ever programming language to use threads, by means of threading libraries. However, you do not necessarily need multi-threading for this - you can just tap into the window messages sent from the OS to the application.
What you can do in Windows is to compile your program as a Windows application with a
Wndprocmessage callback function (check out Windows API beginner learning materials), then listen to for exampleWM_LBUTTONDOWN(left mouse button down) andWM_KEYDOWN(regular keyboard key down). You can record the last state of the mouse buttons/keyboard keys of interest instaticvariables, then check them both whenever either event happens.Typically you do not use a console in such applications but Windows-specific
WinMainwhich doesn't create a console (unless you ask for it manually).