Java: how to disable mouse and keyboard system wide - java

Alright, I am not sure if this is even possible with Java specifically, but I am working on a a small program very similar to synergy and I need to be able to completely disable input from the mouse and keyboard on the host computer, but still record the input within the program. I can not think of any clean and robust ways to do this with Java. Is this possible?

Any way you will have to use JNI for such a purpose.Have a look at this blog ,it will give you some idea.

Related

Get keyboard input from user in java with the program running in background

I once saw a youtube video here and I thought that it would be good exercise to code it myself in java. The Problem is that i can't seem to find a way to read Keyboard input from the user while the program runs in the background, the obvious reason is that it would be dangerous to read the input from the user without the user knowing. I am open for different alternativ ways if there are any.
Hey I can't find a way to do this in core Java, but here is a github repo you may find useful. It seems to be a global key listener in Java.
Hopefully that GitHub repo helps but use it at your discretion, I'm sure you understand the potential dangers of creating something like this!

Detect program GUI using Java

Is there any Java code can help to detect another program GUI part by part?
For example, detect the size of the GUI, detect the location of the button.
Selenium does something similar to this but it is really not there. It will work only for browser-based apps/programs/sites. But if your target programs are browser-based, it will probably be a great tool.
For desktop programs, you might give a look to the createScreenCapture(Rectangle) method from the java.awt.Robot class to get a BufferedImage with the contents of the screen, and then it is up to you to try to make sense of the image, which would not be easy. Also, you might use the Robot to try to juggle out windows as needed, press buttons, type text, or whatever is needed to find out what you want. All of this will be a lot of work.

Controlling mouse when Java window is out of focus

I'm interested in writing a program that will assist me in marking exam papers online. I would like to use the keyboard to control the mouse eg if I press '1' then the mouse will be sent to a specified location and click there. This will double my work output at least. The problem is marking is done through Internet Explorer so the Java program will be out of focus. From searching this site I found that someone has written a library that can receive keyboard input out of focus but I couldn't find any such thing for mice (I don't think Java Robot works out of focus).
Does anyone know whether such a program is possible in Java using standard libraries?
The problem of course is capturing key presses when Java is not in focus. You have three main options as far as I can tell:
Write your own JNA or JNI code to register your hot keys, or
Find a library that does this and call its methods, or
Use a scripting program like AutoIt (if this is Windows) that is linked to your Java program, such as with sockets linking the standard inputs and outputs of both programs.
I have used the 3rd option successfully, but in fact for me, it was usually easier just to do everything in AutoIt.
Note that this statement is not true:
(I don't think Java Robot works out of focus).
The Java Robot doesn't require that a GUI has focus, and in fact does not require that a GUI be running at all.

How to put a text-interface based on system.out.print on a GUI? - JAVA -

I did a project for university (it is a personal implementation of Zork the Game). As asked I did it with a text interface, using system.out.print. Is there a way to "put the text interface in a GUI" ? I mean for example a simple window with 2 fields, one that displays text output and one for the text input by keyboard.
I downloaded windowsBuilder for eclipse but.. I dont know what to do! :(
Thanks!
Sure there is, just change the output stream for System class. Create a PrintStream that will write out your data to your swing components and then replace it in the System class to use it.
System.setOut(printStream);
If you're doing this for a text game, I'd recommend using a Glk library. Glk is a cross-platform windowing I/O system designed for text games. You may have to write a JNI interface since the libraries tend to be written in C: an existing project called GlkJNI is meant to work the other way around, so a C program can use a Java UI, but it might be helpful anyway.
For an example of how to create a GUI that does what you are asking, take a look at this article: http://www.comweb.nl/java/Console/Console.html
This does not use best practices for building a GUI, but for quick and dirty, it'll get you started. You really should read up on how to properly write a Swing application, though, if this is going to be something you are serious about.

a program, running on the background (JAVA)

i want to write a clock program, that should run at background and broadcast the current time according to the system if the keys "1" and "2" are pressed together. i already have a program itself (including audiofiles and appendings) so everything i need, is to find the way to make the program window inactive, but to do it in such way that it will activate when the keys are pressed. what can i do?
On Linux with KDE you can use khotkeys to set up a keyboard hotkey which will send e.g. a dbus message to your program to tell it to reactivate. I don't know if 1 and 2 together is an allowable hotkey - it doesn't make much sense because it will likely cause a 1 or 2 to be inputted into the program you are currently using, which may or may not do anything but it's better to use a key like ctrl, alt or the windows key to avoid that problem.
In other environments / operating systems there may be something similar to khotkeys, I don't know.
I dont think Java can help you here - you're looking at something like a TSR, which unfortunately is not a Java thing. They went the way of the dinosaurs anyway, along with MSDOS.
You've to go native for something like this on the modern operating systems.

Categories