hold keyboard key

This is a discussion on hold keyboard key within the C++ Programming forums, part of the General Programming Boards category; Hi all, I have a program where i press a key and something happens, using Code: UCHAR keypressed[256]; and i ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    12

    Question hold keyboard key

    Hi all,
    I have a program where i press a key and something happens, using
    Code:
    UCHAR keypressed[256];
    and i use it by
    Code:
     BLAR.keypressed[DIK_F]
    this is a KEY PRESS though, and i want the effects of the key to stay even after the user has let go of the key.

    So i press F and hold, it blocks keyboard input from 1,2,3,4,5,6 however, when i let go, i can press 1,2,3,4,5,6 again. I want a solution where i can press, let go and still not be able to press the 1,2,3,4,5,6

    Thanks

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    What OS are you using? How does it blocks the input?
    Give us some code

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    Im using Windows 7 - OS
    Using Windows Visual Studio 2008

    Not sure what code you need but this is how i check for keyinput and the code before is the only code i have to define keypress.

    Code:
    void CheckForKeyInput()
    	{
    		DX_structure.m_keyboard->GetDeviceState(sizeof(UCHAR[256]),(LPVOID)&keypressed);
       	}

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    12

    Question

    ok, i have tried a different approach which i cant figure out is going wrong

    the program starts off so i cant press 1-6 or 0
    by holding down F i can press 1-6 and 0, however, i thought pressing it once would change ignition to true and therefore, work without holding F down?

    Code:
    bool ignition;
    
    	ignition = false;
    
    	if (AdventureGame.keypressed[DIK_F] && (ignition == false))
    		ignition = true;
    
    	if (AdventureGame.keypressed[DIK_G] && (ignition == true))
    		ignition = false;
    
    	if (AdventureGame.keypressed[DIK_0] && (ignition == true))
    		GEARBOX.SetPositionX(-1),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_1] && (ignition == true))
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(-1),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_2] && (ignition == true))
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(-1),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_3] && (ignition == true))
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(-1),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_4] && (ignition == true))
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(-1),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_5] && (ignition == true))
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(-1),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_6] && (ignition == true))
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(-1);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (free)glut and keyboard repeat rates
    By xp190 in forum Game Programming
    Replies: 1
    Last Post: 02-26-2010, 09:28 AM
  2. Fake a Keyboard Interrupt.
    By nicka in forum Networking/Device Communication
    Replies: 0
    Last Post: 09-04-2009, 03:19 AM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  4. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  5. Registery with api?
    By ismael86 in forum Windows Programming
    Replies: 1
    Last Post: 05-14-2002, 10:28 AM

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