Detect if user is using ANSI or ISO keyboard button layout - java

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

Related

How to disable google keyboards text advises

I am making an app for teachers and students: student will see some task and he needs to write correct answer. The problem is that, if student write incorrectly (for example "moondaI" instead of "moonday") keyboard will show to user a tip - it will show that "moondaI" is written incorrectly.
How can I disable this feature inside of my app? If you know, it would be nice if you send me some tutorial
from here: https://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_FLAG_NO_SUGGESTIONS
https://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) in your Activity/Fragment
or in xml:
android:inputType="textNoSuggestions"
Further explanation comes from the official documentation here: https://developer.android.com/training/keyboard-input/style.html
The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.
You can combine different behaviors and input method styles with the android:inputType attribute.
Apparently you can also do it at the device level, thought not tried myself:
From the Home screen, select the app drawer, then select “Settings“.
Tap “System“. (Skip this step on some versions)
Select “Language & keyboard“.
Select “Virtual keyboard“.
Choose the keyboard you are using. It’s normally named “Android“, “Google“, “gboard“, “Swype“,etc.
Select “Text correction“.
Enable or disable the options you want:
Auto-correction
Auto capitalization
Double-space period
Show suggestion strip
Next-word suggestions
Reference

Handling characters width in language conversion java swing application

I am working on a swing application which is currently in English.
Now I have to convert it in different languages like Russian, French etc.
The problem is that I have given size to components according to English, and I am stuck in handling characters in conversion.
For example "Hi" is written in 10 characters in some other language.
I cannot change component size. I want to know that what are the ways to do this?
I was looking for something that can change font size to fit the text in the components.
Thanks in advance.
All the commentators already posted the answer. Somehow I'd also like this question to be marked as answered/closed.
So my recommendation is to take a closer look at Layout Managers that calculate a component's screen size on behalf of you. You just specify rules like 'this is left of', or 'that component shall take the main space'. This way it is extremely easy to replace component texts and still have a meaningful screen.
To learn about Layout Managers, follow the fine manual given at https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

Is text rendering possible onto 2D images with Javascript/PHP?

I own a sports apparel company and I'm looking to have an applet built that will allow customers to see how their team names will look in certain colors on jerseys. Below you can see the final result of a competitor site's Flash applet where text is rendered on 2D surfaces/images.
My requirements: I need users to be able to set the font, primary text color, outline text color, and text style (arched or straight).
So my question-- Is this sort of text rendering possible with only Javascript/PHP?
If so, what limitations do you for see? I've been told the arching and outline text color may be issues. I've also been told that I may have to upload library files to a server where the actual rendering may take place.
If not, what scripting would you guys recommend? I'm trying to stay away from Flash because it's slow and costly.
I'll be passing this onto our developers so please feel free to be as detailed as possible. I figure'd I'd save them some leg work!
Thank you!
Depending on how complex you want your graphics to be, html5 drawing abilities could be used. Check Raphaël library, for instance, webGL/canvas renderers already have a lot of features in modern browsers.
As of the solution with server rendering, it's also possible with gd2(php), but imho that would be less convenient, at least try something different from php (btw, what's your backend running on?)
Your competitor's solution with java applet honestly seems the easiest, except that it requires jre, which few people are eager to install =)
That's kind-of a high level question, but yes you can definitely use javascript for it.
If there's a problem with getting characters to look right, you can always save each letter as a separate image and have javascript place them next to each other in preview. I'd try to see how close you could get with the existing fonts first.
Layering the text: one color large font, then a different color smaller font will give you the outline effect your looking for.

how to detect if a users keyboard is in AZERTY in Java?

There is currently a bug in JavaFX (https://javafx-jira.kenai.com/browse/RT-30669, free registration required) which makes it so that if you are using an azerty keyboard layout and specify an accelerator with Z in it, on Mac it only fires when typing a W. I need to work around this bug as I need to release my product now.
So I'd like to detect Mac+Azerty and if so change the accelerator to using W. I know how to detect Mac, and I know how to detect the keyboard's locale (using InputContext#getLocale()) but how do I know if the current locale has an azerty keyboard layout? Do I have to check against a hardcoded list of known locales which use an azerty layout? If so, where would I find such a list?
Just don't "check against a hardcoded list of known locales" as many people may have a french locale with a keyboard that does not matches the locale, if they bought their computer in the US and use it in quebec with a french interface. I am personally worst, as I'm having a dvorak layout... ;-) And I just want to imagine how many variants of spanish-based layout there may be available...
My best and more portable advice would be to not try to detect something that is hardly detectable, but give some "default" keyboard mappings for (e.g.) qwerty keyboards that would work for most of your userbase, and create a configuration panel that enables your user to change the key mapping for your application by typing the new keys, if they don't like the defaults.
edit:
ah... that can be indeed a different problem... maybe you could anyway make a combobox preference for all non-us keyboard on macosx that has keys with a modifier that get changed?
To answer your question more "straightforwardly", here are a few results I found on google:
http://www.coderanch.com/t/412482/java/java/Finding-language-setting-locale-keyboard
http://www.java-gaming.org/index.php/topic,23501.
both lead towards java.awt.im.InputContext:
InputContext context = InputContext.getInstance();
System.out.println(context.getLocale().toString());
I never tried this in java, so I can't help you more than with my google-fu, but I really hope this helps :-)

How do I add spell checking to a JTextArea?

I have a small Java application that has a JTextArea where the user enters text. I would like to add spell checking capabilities to this component similar to the way that Microsoft Word does it, i.e. misspelled words are underlined and a popup menu with corrections is displayed when the user right clicks on the underlined word. Are there any open source libraries for adding this functionality to JTextAreas?
You could implement your own spell checker using a dictionary (can get quite large depending on languages you support), then distance metrics are calculated from the words in the text box to the dictionary. Underlining can be done using font styling, there as applet based sample here.
Jaspell is a Java implementation of the popular Aspell. In there are some explantions of the search algorithms used.
As mentioned previously Jazzy is also great and IBM provides a nice tutorial.
I haven't tried this before, but I came across it a little while ago: http://sourceforge.net/projects/jazzy/

Categories

Resources