How to listen to Mouse- and Keyboard events when Processing Applet is running in fullscreen mode?
in
Integration and Hardware
•
1 year ago
I use processing for some basic visualizations. I achieved to run it fullscreen on a secondary monitor using the following code. However, it seems that the mouse click events are not registered at the built in processing mouse listener. How can I achieve that? I already tried to follow
this approach an added a mouselistener on the top frame, but not improvements.
Class MainFrame:
Class Visualization:
- public class VisualizationController {
- private static MainFrame frame;
- private static void loadVisualization() {
- frame = new MainFrame();
- GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[1].setFullScreenWindow(frame);
- frame.setVisible(true);
- frame.setResizable(false);
- frame.removeNotify();
- frame.setUndecorated(true);
- frame.addNotify();
- }
- public static void main(String[] args) {
- loadVisualization();
- }
- }
Class MainFrame:
- public class MainFrame extends Frame {
- private static final long serialVersionUID = 1L;
- private Visualization vis;
- public MainFrame() {
- this.addMouseMotionListener(new MouseAdapter() {
- @Override
- public void mouseMoved(MouseEvent e) {
- System.out.println("sdf");
- }
- });
- GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[1].setFullScreenWindow(this);
- setLayout(new BorderLayout());
- vis = new Visualization();
- PApplet embed = vis;
- add(embed, BorderLayout.CENTER);
- embed.init();
- }
Class Visualization:
- public class Visualization extends PApplet {
- private static final long serialVersionUID = 1L;
- private Graph graph;
- public Visualization() {
- graph = new Graph();
- loadGraphData();
- }
- private void loadGraphData() {
- graph.addNode(new Node(this, new Position(50, 50)));
- }
- @Override
- public void setup() {
- this.smooth();
- this.frameRate(30);
- }
- @Override
- public void init(){
- if(frame!=null){
- frame.removeNotify();
- frame.setResizable(false);
- frame.setUndecorated(true);
- frame.addNotify();
- }
- super.init();
- }
- @Override
- public void draw(){
- background(0);
- if (graph != null) {
- graph.draw();
- }
- }
- @Override
- public void mouseMoved() {
- //this method is never called :(
- }
- @Override
- public void mouseReleased() {
- //this method is never called :(
- }
- @Override
- public void mouseDragged() {
- //this method is never called :(
- }
- @Override
- public void mousePressed() {
- //this method is never called :(
- }
- }
1