Jump to content

Adding key listener to osbot


Butters

Recommended Posts

25 minutes ago, nosepicker said:

Title says it all. Any way to write my own key listener and add it to OSBot canvas?

Can't seem to find any methods like there is for mouse listener (getBot().addMouseListener())

What Chris said, or if you only need one of keyTyped, keyPressed or keyReleased:

getBot().getCanvas().addKeyListener(new KeyAdapter() {
    @Override
    public void keyTyped(KeyEvent e) {
        super.keyTyped(e);
    }
});

I'm not sure if canvas is the correct place to add the listener, but if it works, it works I guess.

  • Like 1
Link to comment
Share on other sites

16 hours ago, Explv said:

What Chris said, or if you only need one of keyTyped, keyPressed or keyReleased:


getBot().getCanvas().addKeyListener(new KeyAdapter() {
    @Override
    public void keyTyped(KeyEvent e) {
        super.keyTyped(e);
    }
});

I'm not sure if canvas is the correct place to add the listener, but if it works, it works I guess.

It works well. Thank you both.

Link to comment
Share on other sites

20 hours ago, Chris said:

getBot().getCanvas().addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
                
            }

            @Override
            public void keyPressed(KeyEvent e) {

            }

            @Override
            public void keyReleased(KeyEvent e) {

            }
        });

 

https://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html

Very useful. Thanks Chris.

  • Like 1
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...