This question already has answers here:
Global keylogger in Java
(3 answers)
Closed 6 years ago.
I have been searching for a while now for a library that allows me to know which Key-Event was pressed. But not in a focused program/text-field or anything else but as a process that runs in the background.
I'm not trying to write a keylogger but I want to create a program that lets me create shortcuts for key-combinations.
I don't think Java has native support for something like this. Java is really a language of abstraction, it gets you further away from the OS to make developing easier - but also for security purposes.
Key events are core to the OS so you will (likely) need a language or a library has that capability. Check out JNativeHook.
You can achieve this using JNI and Global System hook. Global System hook applies a Key Logger to the whole computer and not the JVM therefore allowing you to capture key presses outside of the JVM.
An example implementation of it can be seen here
Related
This question already has answers here:
Calling Python in Java?
(12 answers)
Closed 3 years ago.
I'm trying to build an OCR desktop application using Java and, to do this, I have to use libraries and functions that were created using the Python programming language, so I want to figure out: how can I use those libraries inside my Java application?
I have already seen Jython, but it is only useful for cases when you want to run Java code in Python; what I want is the other way around (using Python code in Java applications).
I have worked in projects where Python was used for ML (machine learning) tasks and everything else was written in Java.
We separated the execution environments entirely. Instead of mixing Python and Java in some esoteric way, you create independent services (one for Python, one for Java), and then handle inter-process communication via HTTP or messaging or some other mechanism. "Mircoservices" if you will.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Does Java use libraries to determine which commands perform specific actions?
After learning Java for a few weeks now I don't really understand how Java recognises which commands perform specific functions in code.
For example, how does Java know what to do when you use a "do while" loop? And how does Java remember so many different commands, is there some sort of master list or a combination of libraries that document recognised Java commands and their functions?
This may seem like a real noob question, but it's been bugging me for a while and is getting in the way of my understanding of how code, and specifically Java works. Thank you all in advance.
Edit: Just to make this more specific, I was confused because I didn't know how new functionality is added. So, as I understand, new commands and functionality is added to Java using additional packages alongside the JDK, which contains a list of the most fundamental Java commands?
The commands and the full syntax of the language is defined in the Java Language Specification. The Java compiler generates low level instructions (i.e. bytecode) according to that syntax for language constructs like the do-while loop. The JVM is then responsible for executing those bytecodes.
I understood your questions in two ways:
1 - Where does java hold its lots of functions, classes, etc.
2 - How does java work (how does an if/else work) under the code's skin.
First, there is no noob questions, we are all here to learn :)
Second, about the questions:
1 - Java holds its classes in the Java Development Kit (JDK). Because of this, when you create a Java application, you need it installed in your machine, so Java will find a lot of its classes in the installed JDK.
You can expand the amount of classes by adding new packages (jars) to your project. Then, Java will see all the JDK classes and your added jars.
2 - If you mean to "how does java work in a do-while loop or something related, you want to learn about javac, java's compiler.
Javac will get your code and transform into an jar file. The Java Virtual Machine interprets the compiled code to do memory operations.
For exanple, when you assign a variable to java, internally you create a space in memory with the datatype's size.
When you do a while loop, the JVM will use other VM functions to do the job.
That's actually a quite advanced question. I think you can find more about what you want here.
Hope it helps! :)
This question already has answers here:
How can a program control another program?
(11 answers)
Closed 8 years ago.
I wonder is possible to make a bot writen in JAVA, which will open some program(program is under windows), click on the button in this program and type some data, check status of this program(login or logout, this is client for online game).
Which JAVA tools I need ? I think that java robot lib is not enough for this.
Thanks in advance.
You cannot do this using JAVA.
JAVA is a language which is loosely coupled with operating systems, so it can only receive mouse/key messages from underlying OS. Among all the tasks you mentioned , it can only start the program by using Runtime.execute.
If you want to implement a software like this ,you should use Visual Studio and use Microsoft technologies.
This question already has answers here:
How Do I Eject a Volume in Java?
(2 answers)
Closed 3 years ago.
I know that questions like this have been asked before, but I couldn't find any more recent ones and I have a twist to my question.
I've developed an application in Java that is designed to run on removable media, and work on both Windows and Mac. I would like to add a button to safely remove/eject the device, if it is supported (i.e a USB drive). Is there a command line for each operating system that would allow me to do this?
I know that it can be done by an application running on the device to be ejected, because I've seen one that does it, but obviously I understand there are certain limitations to Java.
Thanks in advance
This is something that you will have to do by invoking an auxiliary application. These applications are not platform independent as you wish. So, to do that, find out which OS you are on by using System.getProperty("os.name") and invoke the appropriate command for the detected OS. Invoking applications is done with Runtime.getRuntime().exec(). Search for the commands you need for each OS.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to determine if a screensaver is running in Java?
is there any way you can find out if the screensaver is active with java? I've searched the web but the only things I found was very complicated native code... My program is made for windows only.
Java cannot handle system tasks directly.
You should use JNI (Java Native Interface) or JNA (Java Native Access) to do it.
I haven't tried this code, but they claim to answer your question with JNA as Ammar suggested: Screen Saver State.