Jump to content

I use C++. I'm in the process of making a small dot-based game, where each arrow key moves it in the respective direction. But here's the catch : When you hold a key, Windows tends to pause after the first instance, and then constantly registers the key-press. I intend to eliminate this pause after the first instance of a continuous key-press. Help, anybody?

 

Screw the Key-Pause!!!

 

Thanks!

Nothing to see here ;)

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/
Share on other sites

Link to post
Share on other sites

4 minutes ago, AlexTheRose said:

What library/API are you using? If it’s on GitHub, report it. That shouldn’t be happening tbh. I highly doubt it’s Windows’ fault, but hey, I’ve seen worse out of that damned OS so prove me wrong lol

No, that's just the way Windows works itself. Try holding the right arrow key as you're typing in a field of text. It'll pause after it passes the first letter and then rapidly scroll through the rest of the letters. I doubt this is fixable unless you use some other library or something not using native Windows keyboard functions.

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7428478
Share on other sites

Link to post
Share on other sites

Api name is needed. If youre using win32 then youre most likely using it wrong.

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7428479
Share on other sites

Link to post
Share on other sites

7 hours ago, trag1c said:

Api name is needed. If youre using win32 then youre most likely using it wrong.

 

7 hours ago, AlexTheRose said:

What library/API are you using? If it’s on GitHub, report it. That shouldn’t be happening tbh. I highly doubt it’s Windows’ fault, but hey, I’ve seen worse out of that damned OS so prove me wrong lol

Guys, right now, I'm just testing out this 'game' in a console environment. I use iostream, stdlib, and Windows(for gotoxy()). I don't exactly know the name of the API but as @cdsboy2000 said, try this out too, open Notepad and hold down any key (say 'A'), the first 'A' comes out immediately, but there is a small pause (duration can be adjusted through Control Panel) before the rest of the 'A's are outputted to Notepad. That is my problem...

 

Nothing to see here ;)

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7429567
Share on other sites

Link to post
Share on other sites

1 hour ago, anandgeforce said:

 

Guys, right now, I'm just testing out this 'game' in a console environment. I use iostream, stdlib, and Windows(for gotoxy()). I don't exactly know the name of the API but as @cdsboy2000 said, try this out too, open Notepad and hold down any key (say 'A'), the first 'A' comes out immediately, but there is a small pause (duration can be adjusted through Control Panel) before the rest of the 'A's are outputted to Notepad. That is my problem...

 

That would definitely occur with stuff like iostream and stdlib (or honestly, I think just in a console environment in general). I would say your next choice would be to make a simple GUI with OpenGL or something so that it's not strictly text-based.

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7430032
Share on other sites

Link to post
Share on other sites

2 hours ago, cdsboy2000 said:

That would definitely occur with stuff like iostream and stdlib (or honestly, I think just in a console environment in general). I would say your next choice would be to make a simple GUI with OpenGL or something so that it's not strictly text-based.

He's opening up a big can of worms if he jumps from console to openGL. Win32 API for GUI isn't to bad to use, or there is Qt as well. All of which are a lot simpler than OpenGL.

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7431027
Share on other sites

Link to post
Share on other sites

3 hours ago, trag1c said:

He's opening up a big can of worms if he jumps from console to openGL. Win32 API for GUI isn't to bad to use, or there is Qt as well. All of which are a lot simpler than OpenGL.

I don't do that much work with C++ but I just figured any GUI in general would do the trick. Thanks for the suggestion :)

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7432407
Share on other sites

Link to post
Share on other sites

I think you might need to use a library. Assuming you're only targeting windows, you can

#include <Windows.h>

Then use https://msdn.microsoft.com/en-us/library/windows/desktop/ms646301(v=vs.85).aspx to get the key state. 

HTTP/2 203

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7434868
Share on other sites

Link to post
Share on other sites

I am guessing you are using something like if(keypressed){//do something}. Instead use a separate bool variable. Then set it to true when the key is pressed, and set it to false when the key is released. Then, inside you need a game update loop, and inside that put

if(boolVariable)

{

    //do something

}

 

That should remove the effect of the key pause.

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7435508
Share on other sites

Link to post
Share on other sites

On 14/03/2016 at 8:37 AM, cdsboy2000 said:

That would definitely occur with stuff like iostream and stdlib (or honestly, I think just in a console environment in general). I would say your next choice would be to make a simple GUI with OpenGL or something so that it's not strictly text-based.

That is a viable option, although I'm afraid it's not exactly feasible. I don't have time to afford, to start learning something totally new... I'm still in high-school!

Nothing to see here ;)

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7441325
Share on other sites

Link to post
Share on other sites

On 15/03/2016 at 0:58 AM, colonel_mortis said:

I think you might need to use a library. Assuming you're only targeting windows, you can

#include <Windows.h>

Then use https://msdn.microsoft.com/en-us/library/windows/desktop/ms646301(v=vs.85).aspx to get the key state. 

That is a very feasible option! I shall definitely look into it.

 

Thanks!

Nothing to see here ;)

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7441332
Share on other sites

Link to post
Share on other sites

On 15/03/2016 at 5:09 AM, Oblivion181 said:

I am guessing you are using something like if(keypressed){//do something}. Instead use a separate bool variable. Then set it to true when the key is pressed, and set it to false when the key is released. Then, inside you need a game update loop, and inside that put

if(boolVariable)

{

    //do something

}

 

That should remove the effect of the key pause.

"I am guessing you are using something like if(keypressed){//do something}."

 

That's exactly what I do! Here's the exact code :

// random shit...
while(1)
{
     if(kbhit!=0)
     {
           int keypress=getch();
           switch(keypress)
           {
                case bullshit...
           }        
     }
}
// random shit... yet again!

How exactly do I replace this with the bool variable?

 

Thanks man!

 

Nothing to see here ;)

Link to comment
https://linustechtips.com/topic/565178-screw-the-key-pause/#findComment-7441352
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×