Thread: Generating *Keyboard Events* thru programming ???

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    1

    Unhappy Generating *Keyboard Events* thru programming ???

    Hey guys

    I want to create a simple program to post some specified key events on a aregular basis for win32, but i do not know what libs and methods to use. The overall strucuture will be as follows :

    =============
    Code:
    int main()
    {
        while(true)
        {
            //post a <num_pad_5> event
            //wait 100ms
            //post a <num_pad_enter> event
            //wait 3000ms
        }
    }
    =============

    Thats it. Please guide me and tell me what libs and methods to use. I am using VC98. It will be great if you can tell me some links too, but basically I am looking for some straight forward lines of code.

    TY

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I'm not sure there is a straightforward way to do what you want. I encourage you to be very specific about what you are trying to do. For example, if you want to monitor keystrokes resulting in ASCII/unicode chars then that program will be different than if you want to monitor all keystrokes, whether they result in a char being displayed or not (for example the tab key, shift key, arrow keys, etc.) For the former you could look at individual char in the input buffer and whenever a certain char is encountered do a certain task. For the latter you may want to monitor virtual key (VK) values, I believe they are in winuser.h. To have the program wait for a predetermined duration before proceeding I'd suggest looking up Sleep(), I believe it is in windows.h.


    Who knows, you might end up with something like this:
    Code:
    while(1)  //an infinite loop
    {
       if(kbhit())  //non-std way to recognize keystroke happened
      {
    	 if(VK_Q)  //if key hit was q 
    	   //do something
    	 else if(VK_ALT) //if key hit was Alt key
    	   //do something
    	 .
    	 .
    	 .
       }
       Sleep(100); //pause program for 100 milliseconds
    }
    You're only born perfect.

  3. #3
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating random 2D mountains/terrain
    By Flaug in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2009, 02:49 PM
  2. Doxygen failing
    By Elysia in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-16-2008, 01:24 PM
  3. Generating a random number?
    By Konspiracy in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 12:33 AM
  4. help with generating numbers
    By kurz7 in forum C Programming
    Replies: 8
    Last Post: 08-06-2003, 08:29 AM
  5. What kind of code do u want a front-end designer generating?
    By MovingFulcrum in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-15-2001, 06:45 PM