Difference between revisions of "Modules/input/Usage"

From MSX Game Library

< Modules‎ | input

(Created page with "Library configuration (<tt>msxgl_config.h</tt>): <syntaxhighlight lang="c"> // Input module setting #define INPUT_USE_JOYSTICK TRUE // Add functions to handle joystick using...")
 
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
Library configuration (<tt>msxgl_config.h</tt>):
+
Check joystick bouton example:
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
// Input module setting
+
u8 joyStat = Joystick_Read(JOY_PORT_1);
#define INPUT_USE_JOYSTICK TRUE // Add functions to handle joystick using I/O port
+
if (IS_JOY_PRESSED(joyStat, JOY_INPUT_TRIGGER_A))
#define INPUT_USE_KEYBOARD TRUE // Add functions to handle keyboard using I/O port
+
{
#define INPUT_USE_MOUSE TRUE // Add support for Mouse handling functions
+
// Joystick A boutton pressed
#define INPUT_USE_DETECT TRUE // Add feature to detect device plugged in General purpose ports
+
}
#define INPUT_USE_ISR_PROTECTION TRUE // Disable interruptions while access PSG registers (needed if you use BIOS or access PSG in your own ISR)
+
else if (IS_JOY_PRESSED(joyStat, JOY_INPUT_TRIGGER_B))
#define INPUT_JOY_UPDATE FALSE // Add function to update all joystick states at once
+
{
 +
// Joystick B boutton pressed
 +
}
 +
</syntaxhighlight>
  
// Key update handler
+
Check key example:
#define INPUT_KB_UPDATE FALSE // Add function to update all keyboard rows at once
+
<syntaxhighlight lang="c">
#define INPUT_KB_UPDATE_MIN 0 // First row to update
+
if(Keyboard_IsKeyPressed(KEY_RETURN))
#define INPUT_KB_UPDATE_MAX 8 // Last row to update (10 for numerical-pad, 8 otherwise)
+
{
 +
// "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>
 
</syntaxhighlight>

Latest revision as of 23: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
}