Wacky Jacky Posted April 30, 2023 Share Posted April 30, 2023 Hi there, like the title suggests, is there a bug where key listener's breaks after a while? I have found that when minimizing the osbot client and opening it (sometimes after few times) and after (some amount of time) the hot keys stopped working. When I kept the game open and not minimized it also occurred but way later, this happens to my script and other scripts I tested using hotkeys. My testing methods are not that amazing or consistent but so is this supposed bug, I can't reproduce it at a constant state. Online minimizing and waiting seems to do the trick. Maybe I am just implementing it wrong, here is my code: @Override public void onStart() { //GUI stuff getBot().getCanvas().addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { //int key = e.getKeyCode(); } @Override public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_H && !hidePaint){ log("Hiding Paint"); hidePaint = true; } else if (key == KeyEvent.VK_H){ log("Un-hiding Paint"); hidePaint = false; } } @Override public void keyReleased(KeyEvent e) { //int key = e.getKeyCode(); } }); This is my setup to hide the onPaint. Maybe I am doing it wrong, or maybe it is a bug, all feed back is welcome! Even feedback not related to this whole "bug" is welcome, if this code snippet can be improved please, let me know, I am learning here. Quote Link to comment Share on other sites More sharing options...
Wacky Jacky Posted May 1, 2023 Author Share Posted May 1, 2023 Thanks to the off site replies, this code isn't the best way of doing it. The alternatives fixed the issues for me. If somehow other people have issues, don't do : getBot().getCanvas().addKeyListener(new KeyListener() but do for example: getBot().getKeyListeners().add(hotkeySensor); Quote Link to comment Share on other sites More sharing options...