Difference between revisions of "Modules/input"
From MSX Game Library
< Modules
(Created page with "{{MODULE |name=input |category=Core |dependency1= |dependency2= |dependency3= |sample1=s_joystk |sample1_desc=joystick |sample2=s_keybrd |sample2_desc=keyboard |sample3=s_mous...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 2: | Line 2: | ||
|name=input | |name=input | ||
|category=Core | |category=Core | ||
+ | |image=raw.githubusercontent.com/aoineko-fr/MSXgl/main/engine/doc/img/sample_joystick.jpg | ||
|dependency1= | |dependency1= | ||
|dependency2= | |dependency2= | ||
|dependency3= | |dependency3= | ||
|sample1=s_joystk | |sample1=s_joystk | ||
− | |sample1_desc= | + | |sample1_desc=Joystick |
|sample2=s_keybrd | |sample2=s_keybrd | ||
− | |sample2_desc= | + | |sample2_desc=Keyboard |
|sample3=s_mouse | |sample3=s_mouse | ||
− | |sample3_desc= | + | |sample3_desc=Mouse |
+ | |sample4=s_paddle | ||
+ | |sample4_desc=Vaus paddle | ||
}} | }} |
Latest revision as of 10:01, 17 October 2024
The input module handle input from the general purpose port (better known as the joystick port; including joystick and mouse) and from the keyboard.
Usage
To use this module, include "input.h" in your source code, and add "input" to the modules list (LibModules) in your project's configuration file (project_config.js).
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 }
Samples
See module use cases in the sample programs:
Settings
Library configuration (msxgl_config.h):
// Input module setting #define INPUT_USE_JOYSTICK TRUE // Add functions to handle joystick using I/O port #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 #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) #define INPUT_JOY_UPDATE FALSE // Add function to update all joystick states at once // Key update handler #define INPUT_KB_UPDATE FALSE // Add function to update all keyboard rows at once #define INPUT_KB_UPDATE_MIN 0 // First row to update #define INPUT_KB_UPDATE_MAX 8 // Last row to update (10 for numerical-pad, 8 otherwise)
Dependencies
Dependency on other modules: None
Documentation