-
Macro Program
Hi all, i would like a nudge in the correct direction here, I am wanting to make my own macro program (dont ask why, lol i am a nerd and if somthing interests me i want to make my own lol)
so far this is how its going to be, im going to start simple and only do the keyboard.
1) User enters data (either into a txt file or in a text box) thats the easy part.
2) Program reads data, another easy part.
3) set an execution multiplier for the macro, we will call the variable X, also easy
4) program emulates the data, and does it... i.e. i type 123 into the programs text box, open notepad and hit the start key it types 123 into notepad X ammount of times
step 4 is the one im a bit confused on since ive never tried anything like this.
how will my program know the start key was pressed if its not the active window? and how can i make it emulate a keystroke to acttually type in the data? and how will it automatically send the keystroke to the active window?
like any program, as this one matures ill make it better, maybe logging the mouse (no clue how i could do this without a giant log file of the x,y pos of the mouse lol) or recording the time of the macro so that it executes it the exact same as the user did... i.e [1]-2.1seconds-[2]-3.2seconds-[3]
also any suggestions of neat stuff to add is welcomed :)
-
If you are using windows, you can use the API to emulate keystrokes.
-
-
ok, i have had luck using keybd_event() under hard coded tests (where i coded in they keys to be pressed)
now i made it more dynamic to type out a string entered...
this technically should work as far as i can tell...
Code:
for(int c=0; c<256; c++)
{
if(S1[c]!='\0')
{
cout << (int)S1[c] << "\n";
keybd_event(S1[c], 0, 0, 0);
keybd_event(S1[c], 0, KEYEVENTF_KEYUP, 0);
}
else
{
c=5000;
}
}
but it gives me weird results... when i enter abcd it ends up coming out as 1234 which is 48 units lower than what i actually typed, so i tried adding 48 to S1[c] and abcd gave me an output of "pp" wtf?! lol
i want to stay clear of sendinput() for right now because im not too clear pon how to use it yet, and it will give me somthing to look forward to upgrading too :) this has been a fun learning experience just need a bit of help here :P
-
Ok now this is weird...
i entered ABCD as my string and it comes out abcd... lol how can i make it where it can take lowercase chars? or will i have to filter the string and convert all chars to upper case the use the VK_SHIFT to re convert them back to upper case.... seems like alot of work that isnt needed.
-
got it working for the most part, still need to add support for special chars like ":" and "." and clean it up some.
Code:
for(int c=0; c<256; c++)
{
if(S1[c]!='\0')
{
//cout << (int)S1[c] << "\n"; --no longer needed for now
if(((int)S1[c]>=65)&&((int)S1[c]<=90)) // Capitol letter, Must Press Shift sucka!
keybd_event(VK_SHIFT, 0, 0 ,0);
else //letter is lowercase
{
S1[c] = toupper( S1[c] ); // converts lowercase to upper so that it can actually be lowercase (dont ask)
}
keybd_event(S1[c], 0, 0, 0); // press down our key
keybd_event(S1[c], 0, KEYEVENTF_KEYUP, 0); //and remove our virtual finger from key
if(((int)S1[c]>=65)&&((int)S1[c]<=90)) // it was a cap, Must Release Shift sucka!
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP ,0);
}
else
{
c=5000;
}
}