Closed gareth-edwards closed 3 weeks ago
I've gotten mouse and key events to play together by adding this after the getCanvas().addMouseListener(new MouseListener() { ... });
// this gives the focus back to the frame when the mouse events lose it so that key events are available again getCanvas().addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent arg0) { // request focus back on the frame to restore key listener playerCanvasFrame.requestFocus(); } @Override public void focusLost(FocusEvent arg0) {} });
But I'm not sure if this the intended/best solution!
First: thanks for the amazing library!
I'm trying to make a video player with controls from both keyboard and mouse with spacebar or mouse click. This works with the spacebar or mouse click to stop/start the video. You can use the spacebar as many times as you like at first, but after the first mouse click the spacebar no longer works.
I have tried various ways to attach/re-attach the key and mouse event listeners but it is beyond me! Can you help? Here is the code to replicate:
Many thanks!