Difference between revisions of "Modules/input/Usage"

From MSX Game Library

< Modules‎ | input

(Blanked the page)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
Check joystick bouton example:
 +
<syntaxhighlight lang="c">
 +
u8 joyStat = Joystick_Read(JOY_PORT_1);
 +
if (IS_JOY_PRESSED(joyStat, JOY_INPUT_TRIGGER_A))
 +
{
 +
// Joystick A boutton pressed
 +
}
 +
else if (IS_JOY_PRESSED(joyStat, JOY_INPUT_TRIGGER_B))
 +
{
 +
// Joystick B boutton pressed
 +
}
 +
</syntaxhighlight>
  
 +
Check key example:
 +
<syntaxhighlight lang="c">
 +
if(Keyboard_IsKeyPressed(KEY_RETURN))
 +
{
 +
// "Return" key pressed
 +
}
 +
</syntaxhighlight>
 +
 +
A quicker way to check keyboard is to read a whole keys row at once:
 +
<syntaxhighlight lang="c">
 +
u8 row8 = Keyboard_Read(8); // The row that include the arrow keys
 +
if(IS_KEY_PRESSED(row8, KEY_RIGHT))
 +
{
 +
// "Right arrow" key pressed
 +
}
 +
else if(IS_KEY_PRESSED(row8, KEY_LEFT))
 +
{
 +
// "Left arrow" key pressed
 +
}
 +
</syntaxhighlight>

Latest revision as of 22:17, 7 January 2024

Check joystick bouton example:

u8 joyStat = Joystick_Read(JOY_PORT_1);
if (IS_JOY_PRESSED(joyStat, JOY_INPUT_TRIGGER_A))
{
	// Joystick A boutton pressed
}
else if (IS_JOY_PRESSED(joyStat, JOY_INPUT_TRIGGER_B))
{
	// Joystick B boutton pressed
}

Check key example:

if(Keyboard_IsKeyPressed(KEY_RETURN))
{
	// "Return" key pressed
}

A quicker way to check keyboard is to read a whole keys row at once:

u8 row8 = Keyboard_Read(8); // The row that include the arrow keys
if(IS_KEY_PRESSED(row8, KEY_RIGHT))
{
	// "Right arrow" key pressed
}
else if(IS_KEY_PRESSED(row8, KEY_LEFT))
{
	// "Left arrow" key pressed
}