Jump to content

2.16b Input::getAndClearSysKey replacement of 2.15.1 App::clearKeyState?


photo

Recommended Posts

Hi,

Updating our code to 2.16.b, it seems replacement of App::clearKeyState is Input::getAndClearSysKey.. or?
I would expect same behavior, reading once the key state.. but it seems not to be the case.

Can you check / suggest proper way?

Regards,
Charles

Link to comment

Hello,

Function analogs from App have been moved to Input only for backward compatibility in engine subsystems. It has now been completely removed. Their use has become difficult due to event-based buffered input. Also, these functions could change the input processing logic depending on the order of the call. The isKeyDown, isKeyPressed, and isKeyUp functions remain for key processing. You can also handle keyboard events using callbacks and an event filter.

Link to comment

Hi,

Thanks for precision.

So.. if I want one action and only one action when the user press key 'd'... i shouldn't use Input::getAndClearSysKey(Input::KEY_D) but Input::isKeyPressed(Input::KEY_D) right?
Or should I setup callbacks? Any doc pointer? Or an example maybe?

Regards,
Charles

Link to comment

RIght now you need to write custom app logic for that because if isKeyDown triggers in the current frame, all the conditions like if (Input::isKeyDown(Input::KEY_D)) would be triggerted as well. The same behavior with isKeyPressed and isKeyUp

For example, simple way to achieve a single action when key D is down:

is_d_key_down = Input::isKeyDown(Input::KEY_D); // store key value before each frame

//.........
if (is_d_key_down)
{
    is_d_key_down = false;
    // key logic
}

Or complex filter implementation:

int input_events_filter(InputEventPtr &e)
{
	InputEventKeyboardPtr key = checked_ptr_cast<InputEventKeyboard>(e);
	if (key && key->getAction() == InputEventKeyboard::ACTION_DOWN)
	{
		if (key->getKey() == Input::KEY_D)
		{
			// process event and don't pass it to engine
			// call may not be on the main thread

			//..................
			// your key logic
			//..................

			return 1;
		}
	}

	return 0;
}

int AppSystemLogic::init()
{
	Input::setEventsFilter(input_events_filter);

	return 1;
}

int AppSystemLogic::update()
{
	if (Input::isKeyPressed(Input::KEY_D))
	{
		// unreachable state because we are discarding events in the filter
	}

	return 1;
}

isDown / isUp - simple flag (for 1 frame) that indicates if button is down or up. isPressed - indicates if button is pressed and stores info in-between multiple frames.

Hope that helps :)

  • Thanks 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...