D
D
DimaIs2017-03-03 10:19:54
Programming
DimaIs, 2017-03-03 10:19:54

How to control using the keyboard?

There was a need to make control in the application via the keyboard, but I did not find anything sensible anywhere, only scraps or not quite what I need. For example, I want to control a cube through arrows. Throw some material, I will be glad :) Also, if anyone knows how to ATTEMPT to read for a certain time, well, for example, while the cube is standing, try to count the symbol / number for a second, if it is not there, then at the end of the time stop trying. Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
developer007, 2017-03-03
@DimaIs

snake C++ -> https://code-live.ru/post/cpp-oldschool-snake/
------------
well, you can track keystrokes in a separate thread (google: threads C++)

while(1)
    {
        ch = getch();
        code = static_cast<int>(ch);
            if(ch == 27) // если клавиша esc
                exit(0);
    }

and set some flag, they say the key was pressed
Next, in the drawing function, check this flag and do something
-------- Is there a GetAsyncKeyState
function, does it asynchronously check whether the key is pressed? https://msdn.microsoft.com/en-us/library/windows/d... key constants here https://msdn.microsoft.com/en-us/library/windows/d...
#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{

  while (1)
  {
    cout << "DRAW!!" << endl;

    if (GetAsyncKeyState(VK_SPACE) != 0)
    {
      cout << "jump!" << endl;
    }

    _sleep(100);
  }

  return 0;
}

* the function receives the state of the key even when the window is not in focus, it is minimized somewhere

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question