simple question... how od you simulate...

This is a discussion on simple question... how od you simulate... within the C++ Programming forums, part of the General Programming Boards category; How do you simulate keystrokes? Sorta like a macro but throw c++. Basicly what I want is somethign that will ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    simple question... how od you simulate...

    How do you simulate keystrokes?

    Sorta like a macro but throw c++. Basicly what I want is somethign that will key the keys I tell it to.


    And if possible, how could I make a program run if I hit, for say, crtl+shift+a?

    I am using dev-c++, so please no vc++.

    Thank you!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You can do this with the Windows API function keybd_event.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok thanks msdn is taking over now.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Now it is just not working, maybe I am lost now...

    Here is the prototype...

    Code:
    VOID keybd_event(          BYTE bVk,
        BYTE bScan,
        DWORD dwFlags,
        PTR dwExtraInfo
    );
    Here is my code...

    keybd_event(
    14, //caps lock key
    NULL,
    KEYEVENTF_KEYUP,
    NULL
    );

    Here is the url at the msdn site...

    http://msdn.microsoft.com/library/de...eybd_event.asp

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Okay...you've told the key to go up. Did you ever tell it to go down?
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    well umm, ok anyways...

    how abotu the crtl+shift+a question, is that possible?

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >how abotu the crtl+shift+a question, is that possible?
    I believe so, but I'm not sure how to go about it. Perhaps you can create a shortcut to your program and then edit its properties to use that keyboard combination to activate the shortcut. It's not a C++ question unless you want to write a program that runs infinitely in the background and polls for ctrl+shift+a.
    My best code is written with the delete key.

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    For the letters and numbers tho.... how do I do them.

    Like for caps lock I would use this VK_CAPITAL

    but for the letter "a", this is all it gives me....

    (41)
    A key


    how do I do letters and numbers?



    Edit: I feel like an idoit, I like the creat shortcut thing. It works now! But now for the letters and numbers.

  9. #9
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    VK_CAPITAL is just #define'd somewhere as an integer that represents that Caps Lock key. You can use 41 the same way.

  10. #10
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Granted, it would be wise to define those character codes as constants somewhere in your code (for a few reasons), and then use the constants.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  11. #11
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Note the "VK_" in the macro's name. That stands for Virtual Key which is a internal operating system representation of a set of key presses. All documentation I found this far states that VK_* for normal text chars have the ascci value of that char.
    Last edited by xErath; 12-05-2004 at 01:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-21-2005, 12:41 AM
  2. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  3. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  4. Simple Question from Stupid Person...
    By Monmouth3 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-02-2002, 09:47 AM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM

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