Program that press a key every X time (HELP)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • starfoxone
    New Member
    • May 2010
    • 3

    Program that press a key every X time (HELP)

    I've some real problems finding info or creating a program that works like this:

    Every 5 minute the program will use key F2 (for example)
    Every 10 minute it will use arrow down and later arrow up.

    Any ideas, examples or guides on how the code should look like?


    Hope someone is able to solve this!
    (starfox-one@hotmail.com )
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Do you mean that every few minutes the program can expect the operator to press those keys? Or do you mean that every few minutes the program will simulate depression of those keys in order to affect some other program?

    Comment

    • starfoxone
      New Member
      • May 2010
      • 3

      #3
      I would like to make a program that will simulate depression of some keys in order to affect an other program of mine. To give exact information, I would like to have codes so I can make a program which will:

      Use F1 every 2 minute.
      Use F2 every 4 minute.
      Use left arrow once and right arrow once every 10min.

      Hope you understand me better.

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Are you having problems with:
        1. The timing?
        2. The pressing of the key?

        Do you have any other conditions on the running of the program? If not, you could just use sleep() or usleep() functions to get the program to sleep until it needs to 'press a key'
        If you need the program to be active, you will have to spawn a seperate thread to initiate the keystrokes.

        Comment

        • starfoxone
          New Member
          • May 2010
          • 3

          #5
          Would this works for example?


          #include <iostream>
          #include <windows.h>
          using namespace std;

          int main()

          {
          for(;;){
          int t=60;
          Sleep(1000);
          keybd_event(VK_ F12, 0, 0, 0);
          Sleep(1000);
          VK_F12, 0, KEYEVENTF_KEYUP ,
          cout << "F12 pressed, Eating";
          Sleep(t*1000);

          }
          return 0;
          }

          I haven't touched C++ or any kind of language/code for three years. I'm making this program for my brother who will use it while playing a game called Tibia. F12 ingame is eating food.

          EDIT: I've problem to get it work ingame

          Comment

          Working...