Ruby Win32Api receives a single character that does not block

I am trying to write a simple game that works with two streams, one stream to get input from the user, and another stream to animate some scenes. I can get characters without pressing ENTER just fine, but it is blocked in the animation stream until the user presses a key. Does anyone know how to get a character from the keyboard to not block?

+3
source share
2 answers

If you want to test several individual keys, GetAsyncKeyState()you can use to poll for status. Otherwise, you must implement the message loop and process the messages WM_CHARin your application.

You can access the original win32 functions with a library similar to the following if your environment does not yet support the win32 functions that you need.

RAA - win32-api @ raa.ruby-lang.org

Here are the links for GetAsyncKeyState().

GetAsyncKeyState () @MSDN
Virtual Key Codes @MSDN (used as values ​​for GetAsyncKeyState and other functions)

If you decide to go with the message outline, you will need to implement it in the same stream as the window for your application. A brief description is available here:

Message Loop on Microsoft Windows @Wikipedia

, . , , , . , ; Windows .

, wikipedia. DispatchMessage Windows . Windows WM_CHAR .

DispatchMessage @MSDN
WM_CHAR @MSDN

, /, WM_KEYUP WM_KEYDOWN.

WM_KEYUP @MSDN
WM_KEYDOWN @MSDN

, GetAsyncKeyState() , . WM_ACTIVATE WM_SETFOCUS/WM_KILLFOCUS, , , , .

WM_ACTIVATE @MSDN
WM_SETFOCUS @MSDN
WM_KILLFOCUS @MSDN

+1

rubygame . . RubySDL GoSu .

, , , -. .

0

Source: https://habr.com/ru/post/1742202/


All Articles