Keyboard Input

1.Overview #

Keyboard a core input device for desktop/laptop gamers. Some devices support on-screen keyboards as well as some game devices also support activate keyboard usage(versus only allowed on keyboard entry popups). 

2.Keyboard Functions #

gpe.check_keyboard_down(keyId)

Returns true or false if the key is being pressed now.

Scope: GPE

Return type : bool

Parameters:

  • int keyId – The constant assigned to the keyboard button. Also procecessed the nobutton and anybutton cases.

 

gpe.check_keyboard_pressed(keyId)

Returns true or false if the key was just pressed in frame.
Scope: GPE

Return type : bool

Parameters:

  • int keyId – The constant assigned to the keyboard button. Also procecessed the nobutton and anybutton cases.

 

gpe.check_keyboard_released(keyId)

Returns true or false if the key was just released in frame.
Scope: GPE

Return type : bool

Parameters:

  • int keyId – The constant assigned to the keyboard button. Also procecessed the nobutton and anybutton cases.

 

3.Keyboard Constants #

In GPE we utilize constants with the “kb_” prefix for handling button input. It is important to know their importance when referencing Keyboard Buttons and their states throughout your games

Here is a complete list of the kb_ constants:

[table id=7 /]

*These are all of the constants supported in in the current version of GPE. If any of the keys do not process properly, please notify us immediately and we will make sure there is no cross-platform issues preventing a singularity. *

4.Legacy Keyboard Constants #

In older versions of GPE(1.1.1 and earlier) we previously used the “gp_” prefix to reference keyboard input. Although, still supported;  it is unadvised to further their usage. For those “too deep in the old ways” here is the list below.

[table id=9 /]

5.Examples #

Ripped from the Basic 2d example:

This moves the left-paddle up and down depending on keyboard input:

if( gpe.check_keyboard( kb_w ) && this.gety() > 4 )
{
    this.move_up(4);
}
else if( gpe.check_keyboard( kb_s ) && this.gety2() < gpe.get_scene_height() )
{
    this.move_down(4);
}
if( gpe.check_keyboard( kb_a ) && this.gety() > 4 )
{
    this.move_left(4);
}
else if( gpe.check_keyboard( kb_d ) && this.x() < gpe.get_scene_width()() )
{
    this.move_right( 4 );
}

 

Help Guide Powered by Documentor
Suggest Edit