User Tools

Site Tools


en:tutorials:testing_input_controls

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:tutorials:testing_input_controls [2018/09/22 15:22 (15 months ago)]
sausage
en:tutorials:testing_input_controls [2018/09/22 18:22 (15 months ago)]
Line 1: Line 1:
-====== Testing Keyboard, Joystick and Mouse Inputs ====== 
  
-This is a small routine to test for all types on inputs, and to output their names on to the screen. A good way to check if your usb gamepad works and what the values are. 
- 
-Good also for keyboard testing to get the names of keypresses which you can use in your config files. 
- 
-Start by creating a new [[en:​tutorials:​creating_your_own_project|Creating your own Orx-based Project using '​init'​]]. 
- 
-Open the project. We don't need an ''​Object''​ so remove or comment out this line from the Init() function: 
- 
-<code ini> 
-orxObject_CreateFromConfig("​Object"​);​ 
-</​code>​ 
- 
-Use the core clock in the Init() function to check regularly for input: 
- 
-<code c> 
-orxClock_Register(orxClock_FindFirst(-1.0f,​ orxCLOCK_TYPE_CORE),​ InputCheck, orxNULL, orxMODULE_ID_MAIN,​ orxCLOCK_PRIORITY_NORMAL);​ 
-</​code>​ 
- 
-<WRAP center round tip 90%> 
-**Note:** ''​orxInput_GetActiveBinding''​ only collects an input for the specific frame. A slow custom clock will miss values especially if they are fast inputs like mouse wheel clicks. Therefore, we use the **core clock**. 
-</​WRAP>​ 
- 
- 
-And finally, the ''​InputCheck''​ function to get and display input: 
- 
-<code cpp> 
-void orxFASTCALL InputCheck(const orxCLOCK_INFO *_pstClockInfo,​ void *_pstContext) 
-{ 
- orxINPUT_TYPE inputType; 
- orxENUM buttonAxisOrKeyID;​ 
- orxFLOAT value; 
- orxINPUT_MODE mode = orxINPUT_MODE_FULL;​ 
-  
- if (orxInput_GetActiveBinding(&​inputType,​ &​buttonAxisOrKeyID,​ &​value)) ​ 
- { 
- const orxSTRING pressedInputName = orxInput_GetBindingName(inputType,​ buttonAxisOrKeyID,​ mode); 
- orxLOG("​Input:​ %s, Type: %d, ID: %d, Value %f", pressedInputName,​ inputType, buttonAxisOrKeyID,​ value); 
- } 
-} 
- 
-</​code>​ 
- 
-''​orxInput_GetActiveBinding''​ will populate the ''​inputType''​ and ''​buttonAxisOrKeyID''​ variables which can be used to get the input name using ''​orxInput_GetBindingName''​. This is handy for logging or getting input names that can be used in the config. Typical output will be: 
- 
-<​code>​ 
-[21:15:25] [LOG] Input: MOUSE_X, Type: 2, ID: 0, Value 771.000000 
-[21:15:26] [LOG] Input: KEY_H, Type: 0, ID: 7, Value 1.000000 
-[21:15:26] [LOG] Input: KEY_H, Type: 0, ID: 7, Value 1.000000 
-[21:15:27] [LOG] Input: KEY_H, Type: 0, ID: 7, Value 1.000000 
-[21:15:28] [LOG] Input: MOUSE_LEFT, Type: 1, ID: 0, Value 1.000000 
-[21:16:01] [LOG] Input: KEY_N, Type: 0, ID: 13, Value 1.000000 
-[21:16:01] [LOG] Input: KEY_SPACE, Type: 0, ID: 71, Value 1.000000 
-[21:16:01] [LOG] Input: KEY_SPACE, Type: 0, ID: 71, Value 1.000000 
-[21:16:02] [LOG] Input: JOY_LX_1, Type: 4, ID: 0, Value -0.447379 
-[21:16:02] [LOG] Input: JOY_LX_1, Type: 4, ID: 0, Value -0.833341 
-[21:16:04] [LOG] Input: JOY_1_1, Type: 3, ID: 0, Value 1.000000 
-[21:16:05] [LOG] Input: JOY_1_1, Type: 3, ID: 0, Value 1.000000 
-[21:17:01] [LOG] Input: JOY_LX_1, Type: 4, ID: 0, Value 0.300008 
-[21:17:01] [LOG] Input: JOY_LY_1, Type: 4, ID: 1, Value -0.454551 
-[21:17:02] [LOG] Input: JOY_16_1, Type: 3, ID: 15, Value 1.000000 
-</​code>​ 
en/tutorials/testing_input_controls.txt ยท Last modified: 2018/09/22 18:22 (15 months ago) (external edit)