B B4JExplorer Active Member Licensed User Longtime User Mar 10, 2019 #1 Hi, In order to intercept the ENTER key for a button, as well as the LEFT and RIGHT arrow keys, they are intercepted thus: Code: Copy ' obj_Reflector.AddEventHandler( "btn_Click", "javafx.scene.input.KeyEvent.ANY" ) obj_Reflector.AddEventHandler( "btn_KeyPressed", "javafx.scene.input.KeyEvent.ANY" ) The problem is that the btn_KeyPressed_Event is being triggered twice for any click or keypress. So if you press ENTER, it's triggered two times. If you click LEFT or RIGHT arrow, same thing. As it turns out, this is ALSO true if you comment out the keypressed event above, and uncomment the click event. In that case, the btn_Click_Event gets triggered twice. Does anyone have suggestions about how to avoid this, or to ignore the second trigger somehow? I'd hate to use a global counter, and check whether this is the second time triggered in order to ignore it. Thanks,
Hi, In order to intercept the ENTER key for a button, as well as the LEFT and RIGHT arrow keys, they are intercepted thus: Code: Copy ' obj_Reflector.AddEventHandler( "btn_Click", "javafx.scene.input.KeyEvent.ANY" ) obj_Reflector.AddEventHandler( "btn_KeyPressed", "javafx.scene.input.KeyEvent.ANY" ) The problem is that the btn_KeyPressed_Event is being triggered twice for any click or keypress. So if you press ENTER, it's triggered two times. If you click LEFT or RIGHT arrow, same thing. As it turns out, this is ALSO true if you comment out the keypressed event above, and uncomment the click event. In that case, the btn_Click_Event gets triggered twice. Does anyone have suggestions about how to avoid this, or to ignore the second trigger somehow? I'd hate to use a global counter, and check whether this is the second time triggered in order to ignore it. Thanks,
Daestrum Expert Licensed User Longtime User Mar 10, 2019 #2 It is the KeyEvent.ANY that is causing this, it is being triggered on KEY_PRESSED and KEY_RELEASED. Change it to KEY_TYPED, this will trigger once when a key is pressed then released. Upvote 0
It is the KeyEvent.ANY that is causing this, it is being triggered on KEY_PRESSED and KEY_RELEASED. Change it to KEY_TYPED, this will trigger once when a key is pressed then released.
B B4JExplorer Active Member Licensed User Longtime User Mar 10, 2019 #3 Daestrum said: It is the KeyEvent.ANY that is causing this, it is being triggered on KEY_PRESSED and KEY_RELEASED. Change it to KEY_TYPED, this will trigger once when a key is pressed then released. Click to expand... Daestrum, this is another one of those mysteries that I would not have figured out for days. Unfortunately, the keycode returns UNDEFINED, rather than ENTER or LEFT or RIGHT. I'm using this to get the code: Code: Copy KeyCode = KE.RunMethod("getCode") But I think this is the right track, thanks.. Last edited: Mar 10, 2019 Upvote 0
Daestrum said: It is the KeyEvent.ANY that is causing this, it is being triggered on KEY_PRESSED and KEY_RELEASED. Change it to KEY_TYPED, this will trigger once when a key is pressed then released. Click to expand... Daestrum, this is another one of those mysteries that I would not have figured out for days. Unfortunately, the keycode returns UNDEFINED, rather than ENTER or LEFT or RIGHT. I'm using this to get the code: Code: Copy KeyCode = KE.RunMethod("getCode") But I think this is the right track, thanks..
Daestrum Expert Licensed User Longtime User Mar 10, 2019 #4 Use KEY_PRESSED instead, KEY_TYPED can only handle normal keys that can be printed. Upvote 0
B B4JExplorer Active Member Licensed User Longtime User Mar 10, 2019 #5 Daestrum said: Use KEY_PRESSED instead, KEY_TYPED can only handle normal keys that can be printed. Click to expand... Yep, that did it, we're all set, thanks Daestrum. Upvote 0
Daestrum said: Use KEY_PRESSED instead, KEY_TYPED can only handle normal keys that can be printed. Click to expand... Yep, that did it, we're all set, thanks Daestrum.