a program, running on the background (JAVA) - 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.

Related

Java Detecting when a key is pressed

I am trying to make a program that will run infinitely until I press a button. This program will run in the background so there is no display open at all times.
while(!certainButtonIsPressed)
{
//Do Something
}
How do I make it so that while certainButtonIsPressed is valid while not making a KeyBoardListener class? Is this possible without a Key listener of some sort?
Thanks!
You ask:
I am trying to make a program that will run infinitely until I press a button. This program will run in the background so there is no display open at all times. while(!certainButtonIsPressed) { //Do Something } How do I make it so that while certainButtonIsPressed is valid while not making a KeyBoardListener class? Is this possible without a Key listener of some sort?
So basically what you're trying to do is to trap all the keypresses of platform from a background process, and this is something that core Java cannot do without use of platform-specific native code that you provide, either through some library that you've obtained, or by meshing your Java program with some key-trapping utility. So if your question is, can this be done via just Core Java? And the answer is: no.
If you are looking for non-Java platform specific solutions, then you will need to give further details. My recommendation though is not to use Java for a task that can be performed much more easily and fully with another language, perhaps a scripting language such as AutoIt, if this were for a Windows environment.

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.

Block java hotkeys, like alt+esc, control-alt-delete

I'm building a Java App, and I need to block the hotkeys, like Alt+Tab, Control+Alt+Delete... Basically theses. My application requires this, because it is a control application. If the solution is not possible on java, any one knows another way to do this.
Thanks you!
Edit1: I'm build a "computer manager" that requires a password. If the password is not type or its wrong, the user can't do nothing on computer.
It works like a default login screen view, but with many users. Got it?
Edit2: After users type the password, he can use all (or some, like alt+tab :) these hot keys! Got it? [2]
Generally speaking you can't, because those keys are intercepted by the operating system before they get to Java.
Give us more info about the OS and enviornment you're in and we might be able to come up with workarounds.
I don't think there is an easy, programatic way to do it.
Unless there is some hidden class inside JDK6 I would say that these combinations are handled by the OS (that catches keystrokes in anycase before dispatching them to applications) so your OS will decide what to do wth keystrokes before Java
If something exists, then it's a hack unrelated with Java but more with registry or similar things :)
One of the whole points of CTRL-ALT-DELETE is that it specifically wants to prevent applications from overriding their functionality. If that were not the case then anybody could write an app that brought itself up when CTRL-ALT-DELETE was pressed and either made itself look like the 'change password' app or the screen saver. Either case would allow the app to steal passwords from people.

Java: how to disable mouse and keyboard system wide

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.

What's ideal debugging setup? window placement etc

I am interested in knowing Debugging setup that'll allow a programmer to be most productive. Assuming knowledge about debugging in general.
I am mainly interested in knowing how and where you place different windows like the variables window, code window, the stack. Also possibly the relative size of different windows.
I'd prefer if there are screenshots attached and a description of why the setup works for you or one that is efficient.
I mainly use Eclipse and Netbeans.
Most productive? That's going to vary greatly from person to person. You shouldn't focus on what works best for other people or details like precise window placement... figure out what works best for you with some trial and error.
For me, multiple monitors are important. I keep code and tools (Eclipse, SQL manager, etc) open on one, and use the other for the console and the running program (whatever it may be: website, windowed application, etc).
First you have to know how to use the debugger really well and then after that the placement of windows is just frivolous detail, for the most part. It will just fall into place without having to mimic other people's comfort level with the tools.
It sounds like you're looking for a static setup but likely you will show/hide windows depending on what you're debugging and size them to different situations. At least that's what I do. So I would post many screenshots and they'd all look different.
"I'd prefer if there are screenshots attached and a description of why the setup works for you. "
You're exactly right knowing it works for the other person.
In addition to what others have said, one thing that I do with respect to variable windows - Visual Studio gives you 4 different watch windows. I usually put them all into a single tabbed window, and each tab will represent a different programming context. For example, tab 1 will list variables that I usually need to look at when dealing with area A, tab 2 has variables for area B and so on.
Doing this, I find that the watch windows don't get over cluttered and I spend less time setting up variables

Categories