Note that there are some explanatory texts on larger screens.

plurals
  1. POSFML - Rendering a character when the key is pressed?
    primarykey
    data
    text
    <p>So I've got this program that is supposed to imitate a console (with a little coding help from <a href="https://stackoverflow.com/users/1119972/teh-internets-is-made-of-catz">this user</a>):</p> <pre><code>#include &lt;SFML/Graphics.hpp&gt; #include &lt;SFML/System.hpp&gt; #include &lt;SFML/Window.hpp&gt; sf::Color fontColor; sf::Font mainFont; sf::Clock myClock; bool showCursor = true; void LoadFont() { mainFont.loadFromFile("dos.ttf"); fontColor.r = 0; fontColor.g = 203; fontColor.b = 0; } int main() { sf::RenderWindow wnd(sf::VideoMode(1366, 768), "SFML Console"); wnd.setSize(sf::Vector2u(1366, 768)); LoadFont(); sf::Text myTxt; myTxt.setColor(fontColor); myTxt.setString("System Module:"); myTxt.setFont(mainFont); myTxt.setCharacterSize(18); myTxt.setStyle(sf::Text::Regular); myTxt.setPosition(0, 0); while(wnd.isOpen()) { sf::Event myEvent; while (wnd.pollEvent(myEvent)) { if (myEvent.type == sf::Event::Closed) { wnd.close(); } if (myEvent.type == sf::Event::KeyPressed) { if (myEvent.key.code == sf::Keyboard::Escape) { wnd.close(); } } } wnd.clear(); if (myClock.getElapsedTime() &gt;= sf::milliseconds(500)) { myClock.restart(); showCursor = !showCursor; if(showCursor == true) { myTxt.setString("System Module:_"); } else { myTxt.setString("System Module:"); } } wnd.draw(myTxt); wnd.display(); } } </code></pre> <p>I need to be able to let the user type a key on the keyboard, and then render that key on the screen. I'm thinking about using an <code>std::vector</code> of <code>sf::Keyboard::Key</code>, and use a while loop to check what the key is (looping through the <code>std::vector&lt;sf::Keyboard::Key&gt;</code>) without using a whole bunch of <code>if</code> statements, but I don't exactly know how to handle that yet, so I'd like to know if there is an easier way to accomplish my main goal. Suggestions? Comments?</p> <p>Thank you for your time, ~Mike</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload