Trying to get Action Keys (backspace, arrow, etc.) in JCEF

Having problems with building or using the JCEF Java binding? Ask your questions here.

Trying to get Action Keys (backspace, arrow, etc.) in JCEF

Postby Hauntedpasta1 » Mon Jul 04, 2022 1:56 am

I'm working on a minecraft mod that uses JCEF, but I ran into a problem, it requires me to use sendKeyEvent(KeyEvent).
Is there any way to call action keys, like backspaces, arrow keys, insert, etc. This is for windows 11 and macOS (intel)

This is the code for it currently this is in the CefBrowserOsr class in java

Code: Select all
@Override
    public void injectKeyTyped(int key, int mods) {
        KeyEvent ev = new KeyEvent(dc_, KeyEvent.KEY_TYPED, 0, mods, 0, (char) key);
        sendKeyEvent(ev);


here is the code for calling the native code.
Code: Select all
/**
     * Send a key event.
     * @param e The event to send.
     */
    protected final void sendKeyEvent(KeyEvent e) {
        try {
            N_SendKeyEvent(e);
        } catch (UnsatisfiedLinkError ule) {
            ule.printStackTrace();
        }
    }
Hauntedpasta1
Newbie
 
Posts: 6
Joined: Mon Jul 04, 2022 1:29 am

Re: Trying to get Action Keys (backspace, arrow, etc.) in JC

Postby Hauntedpasta1 » Mon Jul 04, 2022 6:24 am

Can someone anyone help me pls?
Hauntedpasta1
Newbie
 
Posts: 6
Joined: Mon Jul 04, 2022 1:29 am

Re: Trying to get Action Keys (backspace, arrow, etc.) in JC

Postby FriwiDev » Tue Jul 05, 2022 3:07 am

Code: Select all
KeyEvent ev = new KeyEvent(dc_, KeyEvent.KEY_TYPED, System.currentTimeMillis(), mods, KeyEvent.VK_UNDEFINED, (char) key);

...could work better. Make sure you have the browser on focus before trying to send key presses! (Please note that focus magic with CEF browsers has been a difficult task in the past and will most likely be buggy).
Maintainer of jcefmaven on GitHub.
FriwiDev
Techie
 
Posts: 41
Joined: Sun Jul 09, 2017 4:18 am

Re: Trying to get Action Keys (backspace, arrow, etc.) in JC

Postby Hauntedpasta1 » Tue Jul 05, 2022 7:28 pm

FriwiDev wrote:
Code: Select all
KeyEvent ev = new KeyEvent(dc_, KeyEvent.KEY_TYPED, System.currentTimeMillis(), mods, KeyEvent.VK_UNDEFINED, (char) key);

...could work better. Make sure you have the browser on focus before trying to send key presses! (Please note that focus magic with CEF browsers has been a difficult task in the past and will most likely be buggy).


Let me see if this works with arrow keys :D
Hauntedpasta1
Newbie
 
Posts: 6
Joined: Mon Jul 04, 2022 1:29 am

Re: Trying to get Action Keys (backspace, arrow, etc.) in JC

Postby Hauntedpasta1 » Tue Jul 05, 2022 7:35 pm

backspace send an a with a ~ on top, arrow keys and every other action key isn't doing its thing. A-Z, a-z, and, 0-9 + some symbols are working
Hauntedpasta1
Newbie
 
Posts: 6
Joined: Mon Jul 04, 2022 1:29 am

Re: Trying to get Action Keys (backspace, arrow, etc.) in JC

Postby Hauntedpasta1 » Thu Jul 07, 2022 2:30 pm

Can someone help me again pls!
Hauntedpasta1
Newbie
 
Posts: 6
Joined: Mon Jul 04, 2022 1:29 am

Re: Trying to get Action Keys (backspace, arrow, etc.) in JC

Postby FriwiDev » Fri Jul 08, 2022 4:36 pm

You need to figure out the correct key codes for the arrow keys. You can find them by either searching them online, or debug printing them when receiving key presses on some awt component. Keycodes for the arrows are 37 to 40 (left, up, right, down). They can also be found in the constants KeyEvent.VK_LEFT, ...
Maintainer of jcefmaven on GitHub.
FriwiDev
Techie
 
Posts: 41
Joined: Sun Jul 09, 2017 4:18 am

Re: Trying to get Action Keys (backspace, arrow, etc.) in JC

Postby Hauntedpasta1 » Fri Jul 08, 2022 7:41 pm

ah ok but how do I send the action keys to the browser
Hauntedpasta1
Newbie
 
Posts: 6
Joined: Mon Jul 04, 2022 1:29 am

Re: Trying to get Action Keys (backspace, arrow, etc.) in JC

Postby FriwiDev » Sun Jul 10, 2022 5:51 am

Please use your favorite search engine to find this out way faster in the future. Your question is not really dependent on JCEF, as it applies to all swing components. You need to set the char value to KeyEvent.CHAR_UNDEFINED and change the KeyEvent.VK_UNSPECIFIED to the special key you want. For example KeyEvent.VK_LEFT.
Maintainer of jcefmaven on GitHub.
FriwiDev
Techie
 
Posts: 41
Joined: Sun Jul 09, 2017 4:18 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 14 guests