Auto KeyPress?

This is a discussion on Auto KeyPress? within the Windows Programming forums, part of the Platform Specific Boards category; I am relatively new to C programming (I have been programming for about a month now) and was wondering if ...

  1. #1
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127

    Auto KeyPress?

    I am relatively new to C programming (I have been programming for about a month now) and was wondering if there was a function out there that would automatically press a selected button over and over again. Example: If I wanted the space button hit a bunch of times I could run this program instead of sitting here at the keyboard for a long time. Is this possible?
    ~Sven

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,068
    Yes, it is possible.
    Sent from my iPadŽ

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    State your OS and compiler.

  4. #4
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Windows XP Home and Dev-C++ (4.9.9.2)

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,068
    Yes, it's still possible. Start searching http://www.msdn.com

    They'll have info on basically anything you need to program on a Windows operation system.
    Last edited by SlyMaelstrom; 02-15-2006 at 07:24 PM.
    Sent from my iPadŽ

  6. #6
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    ... via the SendInput API ...

  7. #7
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Thanks but can someone please post an example of how to use that. I don't really understand how that would work. I could use it to create a function that is simpler. Thanks for all of the help!
    ~Sven

  8. #8
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    A moderator should probably move this to Windows programming?

    It's beyond the scope of C alone.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Agreed - moved.

  10. #10
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Never used it before but the msdn docs aren't that hard to decipher:
    Code:
    INPUT Input;
    
    ZeroMemory(&Input, sizeof(INPUT));
    Input.type = INPUT_KEYBOARD;
    Input.ki.wVk = VK_ESCAPE;
    
    SendInput(1, &Input, sizeof(INPUT));
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  11. #11
    Registered User
    Join Date
    Jan 2006
    Posts
    29
    I used SendMessage(handle, WM_IME_KEYDOWN, VK_RETURN, 0); to send enter to a hwnd
    Dev-C++ 4.9.9.2
    Code::Blocks
    Win XP

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    >>automatically press a selected button over and over again

    The button is not in your app then. so you will have to find the buttons HWND (handle). It also has to be the 'default' button to accept SPACE or ENTER as input.



    BTW most advertising reward programs now discount multiple clicks from the same IP or clicks too close together / regular.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  13. #13
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    >> I used SendMessage(handle, WM_IME_KEYDOWN, VK_RETURN, 0); to send enter
    >> to a hwnd

    That only send the message to a defined program, not to the whole system like SendInput.

  14. #14
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    keybd_event()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keypress
    By dandago in forum C Programming
    Replies: 4
    Last Post: 06-10-2007, 09:34 AM
  2. Are auto pointers any good?
    By cunnus88 in forum C++ Programming
    Replies: 3
    Last Post: 04-15-2007, 11:07 AM
  3. auto?
    By cboard_member in forum C Programming
    Replies: 9
    Last Post: 10-07-2005, 12:58 AM
  4. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  5. Disabling "Ready" & Other Auto Status Bar Updates :: MFC
    By kuphryn in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2002, 07:51 PM

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