I have several devices that install as HID keyboard devices in most any operating system and, when used, send a string of text back, just like a keyboard. Is there any way in a Swing app to listen only to a chosen device, ignoring the standard keyboard, and do it without a TextComponent to capture the data? Thanks!
For anyone who comes across via google, etc, here is the solution I finally found.
(This is a solution to the second part of my question, how to capture input without a TextComponent).
I followed this tutorial and attached a KeyListener to my program. This allowed me to capture and parse input, albeit rather awkwardly. I have yet to find a smoother solution to this.
I may come back and add code to this. Please leave a comment if I have not yet done so and you would find it helpful
Related
Hello Guys
I am developing a dictionary application where users can search Arabic <-> Turkish. I'm getting the data from firebase, no problem here. In my algorithm, the user's keyboard language is selected when the user presses the search view. If this language is Turkish, the text entered by the user is listed as Turkish in the search view (+recycle view), sends it to the recycle view and is listed. If that language is Arabic, I list it as Arabic. By the way, you can think of the data I listed as key & value. The Turkish equivalent of each Arabic word is on the same line. So far the app is working fine for me because I am using my phone's default keyboard and I can get the keyboard language.
The problem starts here;
I can't get this keyboard language when user uses custom keyboards published in Play Store. I can't list it because I can't get the keyboard language. I opened a thread on Stackoverflow but was told that I can't access the language of these custom keyboards in any way. So, how can I sort by understanding whether the user is searching in Arabic or Turkish, without picking up the keyboard language or in any way asking the user in which language to search? Thanks in advance and good work.
You will have to maintain a translation in your server, when user searches in one language the corresponding meaning in other language should also be searched, the corresponding meaning will be stored on the server(or on client).
If you can't reliably get the keyboard's locale, that seems like a no-go for what you want to do. But even if someone's using a Turkish keyboard, that doesn't mean they're typing Turkish text, right? Since it basically covers the latin character set - they could even be typing in romanised Arabic! (I don't know how likely that is, but it's possible)
You might want to look into a library that detects languages - from a quick search there are a few, and ML-Kit is a Google library that people seem to recommend for it.
I think whatever you do, you probably want the user to be able to set their input language explicitly - give them the final say (and responsibility for ensuring it's correct!). Similar to how Google Translate does it - you can type and it can guess what language you're using (and it says something like (automatically detected) next to it) but the user gets to explicitly choose
edit since you really want this to be automatic (I'd really recommend giving the user control over this, just in case) could you do something like checking if the characters they've entered are Arabic script?
Doesn't help with romanised Arabic (I don't know if that's really used much at all!) - but if you can assume Arabic uses Arabic script, and Turkish is anything else (or you could do the same with the Turkish characters) then maybe you could take a guess just by comparing their input to a set of potential characters. There might even be a convenient Unicode grouping you can check, but I'm not sure off-hand. Might be worth looking into
I’m working on a modified speech to text feature that should take in a users speech and convert it to text but I want the output text to be exactly what the user is saying. This means I want to detect word disfluency’s such as stammers like “sstttop” and “pppplease”. Ive already written a Java program that does the speech to text but I need to know if it’s possible to modify it to detect speech disfluency. Any input and help would be much appreciated.
I think it's better to improve the structure of the text from the speech delivered by stammer
My first guess would be that you would have to analyze the time that a user spends producing each specific sound. For example, one S could be the 's' sound for half a second whereas two 's's could be represented by the user producing the sound for one second. I understand that this is not completely accurate but best guess I can think of.
I have a webpage with a video. I have to protect this video from capturing it from browser with video capturing programms. I think that for this task i need to check process list or something like this, but to do this i have to use Java. Could anyone give advice how to create this kind of programm. thanks!
I think that it is not possible to prevent user from video capturing. You can make it harder but you will never prevent user from capture screen of his computer. Even if you will control process list of computer (which i guess impossible or impossible for most users) You still cant prevent video capture from computer's video output.
You asking about thing that looks like DRM. History shows that task unsolveable.
You can try identify capturing users (if they will drop your video to torrent). With special unique marks which you can add to video for user. google: steganography
I'm writing a terminal version of my Java application, and this is the first time I do this. I tried Scanner and Console, but as far as I investigated, these classes only allow me to receive user input after he/she finish inputting (no manipulating/filtering).
For example, I want the user inputs his age, but if he inputs a meaningless string, all I can do is validating the string and requesting him to input again. What I really want is only allow him to input integer, i.e when he press any key which is not a number, the character will not be displayed on console. Using Swing and JTextField I can do this easily with DocumentFilter, but with console only, I still haven't found a way.
Any help is appreciated. Thanks all.
Java has something called robot API which u can use to control keyboard mouse etc...
Not the recommended way :)
Since the console is not Java program (its a c program) you have limited way to interface with it, perhaps you can write native API to get more control over it. I have not tried it but if needed use this option.
I've looked at JLine, Lanterna, and others, but I'm not seeing a simple way to find the current caret position in the terminal with these tools. I've looked at a number of escape codes, tput, etc. But, I'm looking for the easiest way to get the current column and row where the caret is located with Java. Maybe I haven't found the right call in these libraries...
What's the easiest way to get the row and column of the caret in the terminal?
I'm looking for a pure textual library so that I can re-write the buffer. I'm aware of ansi escape codes and how to manipulate them to produce the effects I'm after. What I'm trying to do is make a Java prompt library in the vain of Inquirer.js for Node. It has a number of simple ways to get info from the user (lists, questions, split lists, etc). All of it text -- so all of it without a UI, and so non-swing. I don't want swing, I just want a decent terminal UI experience.
Edit2
With the http://docs.oracle.com/javase/7/docs/api/javax/swing/text/Caret.html Caret Interface, you can create a CaretListener Object in order to find a caret position.
So you would have to create a new CaretListener that responds to the GUI, with the getDot() method.
This might help... with code anyway.
http://bestjavapractices.blogspot.com.au/2011/11/get-current-caret-position-in.html
Now at the moment that would only work on a GUI/SwingComponents and I'm not sure if that would work for a terminal application ,which is what you want, where I assume you would be using command line arguments and such to get things to work.
I don't think that you could do this as I think the terminal is really just printing out the output, but I will keep checking for a little while anyway.
If you could tell me what you are trying to use the caret for that would help in my efforts.
Hope this helps.
If it doesn't you may need to look through some more Text Toolkits, such as
JCurses - http://sourceforge.net/projects/javacurses/
Charva - http://www.pitman.co.za/projects/charva/index.html
Current version of Lanterna can read the cursor position using ANSI CSI: https://github.com/mabe02/lanterna/blob/master/src/main/java/com/googlecode/lanterna/terminal/ansi/ANSITerminal.java#L266
And here you can find simple Java solution how to send the ANSI command and read from System.in reported cursor position.
How to read the cursor position given by the terminal (ANSI Device Status Report) in JAVA