Jump to content

Keylistener breaking after a while?


Wacky Jacky

Recommended Posts

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.
 

Link to comment
Share on other sites

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);

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...