It looks like you're new here. If you want to get involved, click one of these buttons!
[MainInput]
KEY_ESCAPE = Quit
KEY_SPACE = CleanScreen
MOUSE_LEFT = CreatePoint
/** Event handler */
orxSTATUS orxFASTCALL InputHandler(const orxEVENT *_pstEvent)
{
orxINPUT_EVENT_PAYLOAD *pstPayload = (orxINPUT_EVENT_PAYLOAD *)_pstEvent->pstPayload;
/* Depending on event type */
switch(_pstEvent->eID)
{
case orxINPUT_TYPE_KEYBOARD_KEY:
{
orxLOG("ID type = %d, ID event = %d", _pstEvent->eType, _pstEvent->eID);
orxLOG("KEYBOARD : InputName = %s, SetName = %s
", pstPayload->zInputName, pstPayload->zSetName);
}
break;
case orxINPUT_TYPE_MOUSE_BUTTON:
{
orxVECTOR pos;
orxMouse_GetPosition(&pos);
orxLOG("ID type = %d, ID event = %d", _pstEvent->eType, _pstEvent->eID);
orxLOG("MOUSE : InputName = %s, SetName = %s, Position = (%d, %d, %d)
", pstPayload->zInputName, pstPayload->zSetName, (int) pos.fX, (int) pos.fY, (int) pos.fZ);
}
break;
}
return orxSTATUS_SUCCESS;
}
/** Update callback */
void orxFASTCALL Update(const orxCLOCK_INFO *_pstClockInfo, void *_pstContext)
{
if(orxInput_IsActive("CleanScreen") && orxInput_HasNewStatus("CleanScreen"))
{
orxLOG("Screen Cleaned !!
");
}
}
/** Inits the tutorial */
orxSTATUS orxFASTCALL Init()
{
orxCLOCK *pstClock;
orxINPUT_TYPE eType;
orxENUM eID;
const orxSTRING zInputNettoyage;
const orxSTRING zInputCreerPoint;
orxInput_GetBinding("CleanScreen", 0, &eType, &eID);
zInputNettoyage = orxInput_GetBindingName(eType, eID);
orxInput_GetBinding("CreatePoint", 0, &eType, &eID);
zInputCreerPoint = orxInput_GetBindingName(eType, eID);
orxLOG("none
"
"- '%s' will clean the screen
"
"- '%s' will create a new point
",
zInputNettoyage,
zInputCreerPoint);
orxViewport_CreateFromConfig("Viewport");
pstClock = orxClock_FindFirst(orx2F(-1.0f), orxCLOCK_TYPE_CORE);
orxClock_Register(pstClock, Update, orxNULL, orxMODULE_ID_MAIN, orxCLOCK_PRIORITY_NORMAL);
orxEvent_AddHandler(orxEVENT_TYPE_INPUT, InputHandler);
return orxSTATUS_SUCCESS;
}
[12:54:59] [LOG]
- 'KEY_SPACE' will clean the screen
- 'MOUSE_LEFT' will create a new point
[12:55:01] [LOG] ID type = 5, ID event = 0
[12:55:01] [LOG] KEYBOARD : InputName = CreatePoint, SetName = MainInput
[12:55:01] [LOG] ID type = 5, ID event = 1
[12:55:01] [LOG] MOUSE : InputName = CreatePoint, SetName = MainInput, Position = (620, 173, 0)
[12:55:05] [LOG] ID type = 5, ID event = 0
[12:55:05] [LOG] KEYBOARD : InputName = CleanScreen, SetName = MainInput
[12:55:05] [LOG] Screen Cleaned !!
[12:55:05] [LOG] ID type = 5, ID event = 1
[12:55:05] [LOG] MOUSE : InputName = CleanScreen, SetName = MainInput, Position = (620, 173, 0)
Comments
Most events in orx have a begin and an end event. So I believe this behavior is normal, one event should be for the key/button down and the other for the key/button up.
Well, it seems that I had misunderstood how events were dealt with : I though that it was 1) source of the input (keyboard, mouse, etc.) then 2) type of input (on, off, etc.)
But it was the contrary.
Thank you : now it works as I wish.
In another hand, as source of the input is dealt with an array, it makes me wonder "how can you have several types in the handle call ?"
I add the "MOUSE_RIGHT" to "[Main Input]" to click both right and left buttons at the same time : it results with 2 handle calls, one for each button.
In addition to Knolan's answers, I wanted to point out that you could also handle the inputs directly in your logic code by calling orxInput_IsActive()/orxInput_HasNewStatus().
For your last question, I'm not sure I understand it correctly either, but in case you're wondering how to use "combinations" ie. have an input trigger when both left *and* right click are pressed, you need to use the config property CombineList, which is a list of all inputs that will only be active when all their bound keys/buttons are pressed.
Example:
Config
Parry now requires both left and right clicks to be triggered simultaneously. If only one left or right is clicked, Parry will be inactive.
However, when Parry is active, Attack & Block will also be active as Attack only requires left click and Block, right click.
The easy way to handle this is to check for Parry before checking for Attack or Block:
There are other ways to handle combinations by switching from one input set to another (like for example, when "Ctrl" is pressed, you can switch to a different input set to handle all the ctrl+XXX combinations, and when it's released you go back to the original input set), but it might be overkill in most situations.
On this topic, note that you can have more than input set active at a time (for example, the in-game console activates an input set in the background to handle all console-related inputs).
I was so persuaded that I needed to use a handler to manage my inputs that I forgot that it existed a simpler way to do so (while, in the same time, I did use orxInput_isActive() in my Update function) :pinch:
My second question was more a general one : what are the cases or do you have examples where the PayLoad arrays have more than one element ?
As it's a general question, I guess the answer depends of the type of event to deal with.
In my specific case, by trying the CombineList property, I succeeded to have more than one element in the PayLoad arrays.
Only entries with a type != orxINPUT_TYPE_NONE are filled and relevant.