Key Listener - ilovethisid/Educational-Ascii-Game-engine GitHub Wiki

Key Listener는 키 입력을 검사하는 독립된 스레드로 동작합니다.

The key listener is executed independently of the main function using a thread. The goal is to receive key input in real time, so the time to check the key input should be as short as possible. The confirmation of key down and double-click input takes a long time, so I applied it only to arrow keys as an example, and you can apply it to other keys if you want.

Normal Key Input

When thread receive a key input, thread replace KeyListener’s flag with true. Returns flag and replaces flag with false when main function checks key input through keycheck. It works the same for the case below.

key down input

In addition to the default input, the KeyListener also supports key down input. The time recognized by the key down can be set by modifying the KDT macro. The key down input records the first time you enter. Afterwards, if the key input no longer comes in, replace the saved time with NULL, or flag with true if the key is pressed for more than a specified time.

Double click Input

A double-click input stores the input state for each input. If the input state changes from true to false, record the time. If the difference between the recorded time and the current time when false to true is less than DCT macro, replace the flag with true.

Non-Input Features

  • Reset
    Replace all saved flags with false. Use to write down a user’s name or reset the game.
  • ReturnF & exit
    Feature for exiting threads. Using exit, the return of ReturnF is replaced by false, ending the thread.