Results 1 to 4 of 4
  1. #1
    lolman40's Avatar
    Join Date
    May 2017
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0

    Question C++ check if button pressed

    In c++ how do i check if a key is pressed ( not GetAsyncKeyState/GetKeyState because when I hold it down it spams the command)

    Code:
    int main()
    {
    	while (1)
    	{
    		if (GetAsyncKeyState(VK_INSERT)) {
    			//Command
    		}
    	}
    }
    Last edited by lolman40; 06-18-2017 at 06:45 AM.

  2. #2
    affe2626's Avatar
    Join Date
    Apr 2015
    Gender
    male
    Location
    Sweden
    Posts
    552
    Reputation
    146
    Thanks
    151
    My Mood
    Angelic
    Quote Originally Posted by lolman40 View Post
    In c++ how do i check if a key is pressed ( not GetAsyncKeyState/GetKeyState because when I hold it down it spams the command)

    Code:
    int main()
    {
    	while (1)
    	{
    		if (GetAsyncKeyState(VK_INSERT)) {
    			//Command
    		}
    	}
    }
    Code:
    GetAsyncKeyState(button) & 1;

    So, your code would look like:
    Code:
    int main()
    {
    	while (1)
    	{
    		if (GetAsyncKeyState(VK_INSERT) & 1) {
    			//Command
    		}
    	}
    }
    Last edited by affe2626; 06-18-2017 at 11:53 AM. Reason: [CODE] tags

    Always PM me when trading, I've been hacked on my Skype previously
    [img]https://**********.com/addskype/affe2626.png[/img]

  3. #3
    lolman40's Avatar
    Join Date
    May 2017
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0
    Quote Originally Posted by affe2626 View Post
    Code:
    GetAsyncKeyState(button) & 1;

    So, your code would look like:
    Code:
    int main()
    {
    	while (1)
    	{
    		if (GetAsyncKeyState(VK_INSERT) & 1) {
    			//Command
    		}
    	}
    }
    It is still spamming tough.

  4. #4
    ThePureSkiller's Avatar
    Join Date
    Oct 2016
    Gender
    male
    Posts
    20
    Reputation
    10
    Thanks
    1

    code tag

    dude that is simple code


    Code:
    int main()
    {
    	bool pressed = false;
    
    	while (1)
    	{
    		
    		if (GetAsyncKeyState(VK_INSERT) && !pressed) {
    			pressed = true;
    			//Command
    		} else {
    			pressed = false;
    		}		
    	}
    }

Similar Threads

  1. [Help Request] button press loop
    By stevonator in forum Call of Duty Modern Warfare 3 Coding, Programming & Source Code
    Replies: 8
    Last Post: 08-17-2012, 11:10 AM
  2. Cycling through threads on button press
    By Azureum in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 0
    Last Post: 09-06-2010, 12:55 AM
  3. [CODE] Button Pressed[Solved]
    By Golden. in forum Visual Basic Programming
    Replies: 16
    Last Post: 07-28-2010, 09:29 PM
  4. i pressed the back button sorry
    By brownsfan91 in forum WarRock Korea Hacks
    Replies: 7
    Last Post: 12-03-2007, 09:20 PM
  5. i pressed the back button sorry
    By brownsfan91 in forum WarRock Korea Hacks
    Replies: 0
    Last Post: 11-30-2007, 06:13 PM