Thread: Using Keyboard to Control Variables

  1. #1
    Registered User mr_raging_money's Avatar
    Join Date
    Mar 2012
    Posts
    18

    Question Using Keyboard to Control Variables

    I am writing a program that moves a simple rectangle around a graphics window, and I want to use a WASD style control scheme to do this. I was wondering how I would get the box to move according to what key I press. I have tried making
    Code:
    examplevariable = getch();
    and that didn't work. I know there must be a way to do this but I don't know what it is. I can't find this browsing the web for some reason. I guess I don't know what to search.

    Can I have some other ideas on how to do this?

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Isn't one thread enough?

    Read the example variable with getch() inside a loop, evaluate it (is it a,s,d or w?) update coordinates accordingly, with the new coordinates reprint the screen. Rinse repeat.

  3. #3
    Registered User mr_raging_money's Avatar
    Join Date
    Mar 2012
    Posts
    18
    sorry, I didn't see your other post until after

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    dupe thread closed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Set Keyboard Focus to a non child control
    By gaurav_13191 in forum Windows Programming
    Replies: 3
    Last Post: 11-06-2011, 01:57 PM
  2. Using threads for control input (keyboard, serial)
    By synthetix in forum C Programming
    Replies: 1
    Last Post: 07-06-2009, 07:43 PM
  3. Control and Keyboard Input
    By Almina in forum C++ Programming
    Replies: 6
    Last Post: 07-30-2008, 10:01 AM
  4. sending something to a rich edit control without keyboard
    By RancidWannaRiot in forum Windows Programming
    Replies: 1
    Last Post: 11-21-2005, 08:53 AM
  5. keyboard control
    By MathFan in forum C++ Programming
    Replies: 1
    Last Post: 04-16-2002, 11:55 AM

Tags for this Thread