Emulating button press.

This is a discussion on Emulating button press. within the C++ Programming forums, part of the General Programming Boards category; I did a brief search and couldn't find anything on this. What I'm wanting to do is emulate a keyboard ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    163

    Emulating button press.

    I did a brief search and couldn't find anything on this. What I'm wanting to do is emulate a keyboard button press. Like, say if the user does something stupid I can make my program hit ctrl+alt+down, or something like that.

    I don't know if it's possible, but if it is, I'd like to mess with some friends

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,535
    you probably mean ctrl+alt+del

    Today's windows.h or conio.h or PDCurses day. Let's celebrate.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    Quote Originally Posted by Mario F.
    you probably mean ctrl+alt+del
    No, on some versions of XP(haven't figured out which ones will, and which wont), ctrl+alt+down(of the four arrow buttons) makes your screen flip. I could also use windowsKey the U then U

    Quote Originally Posted by Mario F.
    Today's windows.h or conio.h or PDCurses day. Let's celebrate.
    is this somesort of indication that windows.h or conio.h will solve my problem?

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,535
    Yes. Been the topic for maybe 4 out of 5 threads for the past hour
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    Quote Originally Posted by Mario F.
    Yes. Been the topic for maybe 4 out of 5 threads for the past hour
    Think you might be able to point me in the direction of a list of functions from windows.h/conio.h ? I've been searching, but the only thing I've found was the clear screen function in conio.

    Boy... am I annoying, or what!

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    A good place to start for win32 specifics is: http://msdn.microsoft.com/library/de...y_category.asp

    In this case, I believe the SendInput function might work.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by System_159
    I did a brief search and couldn't find anything on this. What I'm wanting to do is emulate a keyboard button press. Like, say if the user does something stupid I can make my program hit ctrl+alt+down, or something like that.

    I don't know if it's possible, but if it is, I'd like to mess with some friends
    You can't inject CTRL+ALT+DEL, because it is checked in a very low-level hook.

    Think you might be able to point me in the direction of a list of functions from windows.h/conio.h ? I've been searching, but the only thing I've found was the clear screen function in conio.
    Don't use conio. It's not the standard.

    But basically you can emulate key presses like this (Windows):
    Code:
    INPUT ms;
    ms.type=INPUT_KEYBOARD;
    ms.ki.wVk=0x46;
    ms.ki.dwFlags=0;
    //'f' key down
    SendInput(1,&ms,sizeof(INPUT));
    ms.ki.dwFlags=KEYEVENTF_KEYUP;
    //'f' key up
    SendInput(1,&ms,sizeof(INPUT));
    And like this:
    Code:
    //'f' key down
    keybd_event(0x46,0x45,KEYEVENTF_EXTENDEDKEY|0,0);
    //'f' key up
    keybd_event(0x46,0x45,KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP,0);
    Last edited by maxorator; 09-30-2006 at 12:40 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program keeps shutting off when I press a button
    By Megamanenm in forum Game Programming
    Replies: 2
    Last Post: 01-11-2009, 03:21 AM
  2. Type text = Press button = Display text in Google?
    By Raze88 in forum C++ Programming
    Replies: 4
    Last Post: 03-20-2008, 09:39 AM
  3. render OpenGL geomatry on dialog box button press
    By psychopath in forum Windows Programming
    Replies: 0
    Last Post: 08-20-2004, 09:49 PM
  4. Replies: 0
    Last Post: 06-26-2004, 06:59 PM
  5. MFC: Change the color of static text with button press?
    By BrianK in forum Windows Programming
    Replies: 2
    Last Post: 06-17-2004, 12:03 AM

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