SFML community forums

Help => General => Topic started by: Ragbot on May 09, 2021, 09:02:11 pm

Title: Get Keyboard input without a window(Console)
Post by: Ragbot on May 09, 2021, 09:02:11 pm
I cant get user input without a window,

because I have to use

while(window.pollEvent(event))
{
    switch(event.type)
    {}
}
 

So, is there any way for me too get user input without a window?
Title: Re: Get Keyboard input without a window(Console)
Post by: G. on May 10, 2021, 07:51:27 am
C++ standard input, cin, if you want to get some text or numbers from your console
https://www.cplusplus.com/doc/tutorial/basic_io/

sf::Keyboard::IsKeyPressed if you have other needs...
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Keyboard.php
Title: Re: Get Keyboard input without a window(Console)
Post by: Ragbot on May 10, 2021, 01:31:11 pm
Is there a way to get the input only when it got pressed,

Like a short pulse?
like WM_KEYDOWN?
Title: Re: Get Keyboard input without a window(Console)
Post by: G. on May 10, 2021, 05:25:16 pm
You'd have to keep an array of what keys are pressed, update it every step of your main loop, and when a key is pressed but wasn't pressed before it will mean it has been pressed right now, like a "short pulse" I guess
Title: Re: Get Keyboard input without a window(Console)
Post by: Ragbot on May 11, 2021, 02:11:41 pm
I didn't understand can I like get a pseudo code?

Quote
You'd have to keep an array of what keys are pressed

Like in an array?

so do we do it like this :

if(array.at(array.size()) == sf::Keyboard::K)
{
    // Do stuff //
}
 
is it like that? or