Can we insert Unicode Characters using Robot Class in Java? - java

I am developing a Real time English-Sinhala Unicode translator in java.I did the translation part.But now I want to add the Final output Unicode characters to the currently active window (like a web browser).There's a way to add characters via java Robot class with
Robot.keyPress(//keyInput) method.But is there any way to do this with java Unicode characters like u0200 hex value.If it can't be done with this way what solutions I have to resolve this.Please anyone help me ?

Yes, you can simulate key presses using Robot, as suggested here. No, Robot can't see what's printed on the user's key caps. You're probably going to have to develop a virtual keyboard. When available, Unicode glyphs make usable button labels, as shown here.
Addendum: Note that a KeyEvent represents a keystroke, while Unicode encodes graphemes represented by glyphs. The mapping depends on the keyboard layout, e.g. Sinhala.

Related

Detect if user is using ANSI or ISO keyboard button layout

I'm currently working on a custom key binding mod for Minecraft. Although irrelevant, it gives some context. I'm planning to show a UI with all the buttons on their keyboard where they can click to assign macros to said key, although I don't want to be biased towards one particular keyboard button layout.
Looking at a website called switchandclick they show the differences between ISO and ANSI. ISO which I'm using has a key between left shift and Z, as well as having the return/enter key 2 keys tall rather than 1, with the missing key moved above right shift.
Here is the image from said site:
However, even if ISO is the layout used in Sweden where I live, I'm aware some users may be from different parts of the world, and ANSI is probably more common in America, so I don't want to show an ISO keyboard for ANSI users and vice versa.
I've looked around at various sources, but all I can find when looking for a solution is websites showing the differences between the layouts, rather than showing how to detect them.
So how would I go about detecting if the user has an ANSI or ISO keyboard? Pure Java is preferred but LWJGL 3 is the graphics api in use if that helps with finding a solution. I'm also running Java 17 in case that makes it easier.
As mentioned by #Abra in a comment to the question, there's no way to do that programmatically as there's no protocol between the keyboard controller and the keyboard driver that helps distinguish the layout of the keyboard.
Only option here is to either guess/predict the layout, let the user choose the layout, or simply use the same layout assumed by Windows in osk.exe.
Original answer on this post

How to add two Fonts to java swing components, and make them automatically switch when user switches keyboard input language?

I'm working on an app where User should be able to input some text which contains both English and Persian(Same as Arabic: almost same characters and written from right to left ).
Currently i'm using fonts like Courier New which supports both languages but it looks really Ugly. I Want to use some better looking fonts, but these fonts only support one of these languages and show nonsense characters for the other language. So i need to use them based on text language.
So generally how can I make Java components (especially swing.JTextField, swing.JListBox and swing.JTextComponent) accept two fonts and switch appropriately to have a good looking GUI?
Edit: Here is an example of what i need. Let say user should input something like (FPGA استفاده از ) and all of it in a single swing.JTextField. It means (Using FPGA) and FPGA is an abbreviation, so there is no Persian translation. I need to set a font with a better look and all fonts which support Unicode are ugly for the Persian part.
Now if I set font to something like Times New Roman ,which only supports Latin, then Persian characters would show as empty squares. also if i set font to something like B Nazanin ,which only supports Persian, then Latin characters would show as empty squares. How can I have both fonts in a single Java component in the same time.
InputContext context = InputContext.getInstance();
if(context.getLocale().toString().equals("en_GB")){
.setFont(*font for english keyboard*);
}
else if(context.getLocale().toString().equals("fa_IR")){
.setFont(*font for persian keyboard*);
}

Java unicode fonts

I am developing a java game and I need characters, such as monsters and doors etc. I am trying to include them with the help of chars and unicode. However, some chars, such as a key, '\u26BF', do not show up properly in the terminal of the game, but rather as a box. Do I need to import some special fonts or how else would I solve this problem?
GNU Unifont is reported as containing this Glyph. As it comes under the GNU public licence it is not subject to any licence fee.
Home page: http://unifoundry.com/unifont.html
It has TrueType, which should work wiht Java.
Like people already pointed out in the comments sections, you will have to use another font containing those special characeters.
The font you are using seems to not support those characters, you can download any other font containing those character(s). The character 'u26BF' is a square box in some default fonts (source).
You can find different fonts and even try them out on DaFont and, like #SubOptimal warned you, check the licenses also before you download & use it.

Is there a way to control the keyboard in java without awt.robot

Is there a way to control the keyboard in java without using awt.robot?
Unfortunatly the robot class cannot press every key on an azerty layout.
And I need one of them.
The only solution seems to code the equivalent of robot in C then use java to
call it.
Thanks.
Did you know that you can type any ascii character by
Holding alt
Typing the ascii code for the character on the NUMBERPAD
Releasing alt
You could get the robot to do this for special characters. Not sure if that solves your problem.
Eg: hold ALT, type 1234 on the numberpad, release ALT types Ӓ
According to Java Robot with Azerty vrs Qwerty the Window Licker library (https://code.google.com/p/windowlicker/) supports different keyboard layouts. This might help you.

How Can I detect Unknown/Unassigned Unicode characters in my java program?

I want to write a java program to print Unicode characters. I want to detect and not print Unknown/Unassigned CHaracters (which are shown by a rectangular). I have tried "isDefined" and "isISOControl" from "Character" class, but it does not work.
Does anybody know the solution? it will be a big help for me.
Thanks.
The characters that are shown as a rectangle (on Windows) are ones that aren't available in the font you're using. While you could filter out a lot of them by filtering out undefined and control characters, it's entirely possible that the problem you're running into is that your font doesn't support certain ranges of valid characters (which is typical -- very few fonts define glyphs for all defined Unicode characters).
If your goal is really to remove characters that render as a rectangle, you can use the canDisplay method in Font.

Categories

Resources