javier.serrano Posted November 27, 2018 Share Posted November 27, 2018 Hi, I want to control XBox controller button state to manage actions with holding time confirmation behaviour (press the button for 2 seconds and perform an action). The problem comes that, when the holding time is reached, I want to reset button state in the same way as I do with keyboard keys using engine.app.clearKeyState(). The user must release the button and press again to reactivate key state. When I use ControlsXPad360::clearButton() the button state is only cleared in the current frame. I've attached an example trying to do this, but looks like ControlsXPad360::clearButton() doesn't work in the same way as engine.app.clearKeyState(). What's wrong in my code?. Thanks in advance, Javier main.usc Link to comment
cash-metall Posted November 28, 2018 Share Posted November 28, 2018 Hi, Javier! Your code is correct. However, many controllers imitate the repetition of pressing while a long press (autorepeat). This may depend on the controller model, drivers, operating system settings. clearButton () really works just like clearKeyState (), but autorepeat breaks everything. example code joy->updateEvents(); Log::error("frame[%d] \t state button %d\n", numframe, joy->getButton(ControlsXPad360::BUTTON_B)); if (joy->clearButton(ControlsXPad360::BUTTON_B)) { Log::error("frame[%d] \t === clear Button === \n",numframe); } numframe++; output: frame[00] state button 0 frame[01] state button 0 frame[02] state button 0 frame[03] state button 0 frame[04] state button 0 frame[05] state button 0 frame[06] state button 0 frame[07] state button 0 frame[08] state button 0 frame[09] state button 0 frame[10] state button 0 frame[11] state button 1 //real button press frame[11] === clear Button === frame[12] state button 0 frame[13] state button 0 frame[14] state button 0 frame[15] state button 0 frame[16] state button 0 frame[17] state button 0 frame[18] state button 0 frame[19] state button 0 frame[20] state button 0 frame[21] state button 0 frame[22] state button 0 frame[23] state button 0 frame[24] state button 0 frame[25] state button 0 frame[26] state button 0 frame[27] state button 0 frame[28] state button 0 frame[29] state button 0 frame[30] state button 1 //fake button press frame[30] === clear Button === frame[31] state button 0 frame[32] state button 0 frame[33] state button 0 frame[34] state button 0 frame[35] state button 0 frame[36] state button 0 frame[37] state button 0 frame[38] state button 0 frame[39] state button 0 frame[40] state button 0 frame[41] state button 0 frame[42] state button 0 frame[43] state button 0 frame[44] state button 0 frame[45] state button 0 frame[46] state button 0 frame[47] state button 1 //fake button press frame[47] === clear Button === frame[48] state button 0 frame[49] state button 0 frame[50] state button 0 //real button release frame[51] state button 0 frame[52] state button 0 In your case, we recommend manualy managing the buttons, without using clearButton() joy->updateEvents(); if (joy->getButton(ControlsXPad360::BUTTON_B)) { if (!button_pressed) { Log::error("[%f] button real press \n", Game::get()->getTime()); flag_time_2s = true; } ftime+= Game::get()->getIFps(); button_pressed = true; if (flag_time_2s && ftime > 2.0f) { Log::error("[%f] 2 seconds passed \n", Game::get()->getTime()); flag_time_2s = false; } } else { if (button_pressed) { Log::error("[%f] button real release. \t time: %f seconds \n",Game::get()->getTime(), ftime); ftime = 0.0; } button_pressed = false; } output: [8.149965] button real press [8.370353] button real release. time: 0.220940 seconds [9.200887] button real press [9.355804] button real release. time: 0.156040 seconds [10.282433] button real press [12.277890] 2 seconds passed [14.355497] button real release. time: 4.074118 seconds [16.258760] button real press [16.412865] button real release. time: 0.154864 seconds [17.250240] button real press [19.249041] 2 seconds passed [22.954279] button real release. time: 5.704463 seconds [25.586277] button real press [25.750677] button real release. time: 0.165828 seconds [26.023460] button real press [26.162262] button real release. time: 0.140819 seconds 1 Link to comment
javier.serrano Posted November 28, 2018 Author Share Posted November 28, 2018 Thank you for your response As I don't know my customer's controller and system settings I'll have to manage buttons states myself. Regards Link to comment
Recommended Posts