Macro Program

This is a discussion on Macro Program within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, i would like a nudge in the correct direction here, I am wanting to make my own macro ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    9

    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

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    If you are using windows, you can use the API to emulate keystrokes.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    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

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    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.

  6. #6
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    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;
    		}
    	}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21