How to generate keyboard events that do not have key code in Java?

I use the Robot and KeyEvent classes to generate all the other key events, and they work fine, but I also need the Hangul key (switch Korean keyboard). Obviously, KeyEvent does not have a key code for this key, so I'm stuck :( Is there a way to generate this Hangul key event? Is there a way to use the Windows key code as VK_HANGUL (0x15) instead of KeyEvent key codes? If this is a possible change to all key codes will not be a problem ... Or somehow take the key event once and save it forever somewhere and use it forever ... ???

What I'm trying to do is create an on-screen keyboard with numbers, alphabets, and Korean. Click on the icon and it will generate a key event of the corresponding letter to type the letter. (Everything except switching to Korean works fine.)

Being able to generate a Hangul key event would be nice, but if that is not possible, are there any suggestions on how I could achieve this? Perhaps I could associate each Korean letter with the corresponding alphabet on the keyboard (for example, g is ㅎ on regular keyboards with English and Korean) or something like that, but then how to send it to other applications?

Sorry if this question is so everywhere. I just got lost.

+5
source share
1 answer

I found one solution to the problem. I used JNA to generate keyboard events.

Here are some codes if someone needs them.

Basic information on using the JNA method and keybd_event from User32.dll:

import com.sun.jna.*; import com.sun.jna.Native; import com.sun.jna.platform.win32.User32; import com.sun.jna.win32.StdCallLibrary; public interface User32jna extends User32 { User32jna INSTANCE = (User32jna) Native.loadLibrary("user32.dll",User32jna.class); public void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo); } User32jna u32 = User32jna.INSTANCE; 

And then paste this where you need to generate the key event:

 u32.keybd_event((byte) 0x15,(byte)0xF2,0,0); 

0x15 and 0xF2 is the virtual key code and keyboard scan code for the Hangul / English key that I was looking for, but find the codes for any key you need, and then replace them, and you can generate almost any key event.

For this you will need jna.jar and platform.jar.

0
source

Source: https://habr.com/ru/post/1208752/


All Articles