Getting Callback from OS X When Application Foucs Changes? - java

I am trying to find a way how to write a "software sensor" in Java, running on Mac OS X (10.5), which records each application focus change.
My first idea was to write a "pull sensor" that uses an Applescript, which just returns the name of the app. that is in focus. Obviously this approach is not very good.
Therefore, I was wondering if there is the possibility to get a callback or some kind of notification directly from the operating system, whenever another application gets into the focus.
Thanks in advance!
Cheers Julian

java recieves no events from other applications, so there would be nothing to intercept and record. im sure OSX's SDK has something you could use though. it wouldn't be java based (unless you used JNI or JNA).

Related

How to prevent system from going to hibernate?

I want to develop a Java application, hoping that the system never goes to hibernate when my application running.
The application will be deployed in Windows.
Is there any way to realize this?
There is nothing in java for this.
There are windows API to prevent hibernation. See this thread Prevent windows from going into sleep when my program is running?
You could all call them via JNI or JNA
There are two ways to avoid your system going into Hibernate mode when your application is running:
1) I don't know which Windows operating system you are talking about; but we can disable or enable Hibernation at an operating system level. The enabling/disabling method might differ for different Window versions.
2) Another way would be to write a C++ program that uses Win32 API to interact at system level. After writing the code, you can export it as a DLL library and then use it in the Java program. Below link provides a sample code that will help you achieve similar functionality.
http://www.codeguru.com/cpp/w-p/system/messagehandling/article.php/c6907/JavaC-PC-Standby-Detect-and-Prevent.htm
I had similar problems when i wanted to connect via RDP to my pc, i left teamviewer on, but my pc went to hibernate/sleep and this is my solution how i keep my pc "active".
Try this, go to Control Panel->Power Options:
and there u can select power plan, click on "Change plan settings" and u will get to this screen:
Hope that this will help u.
If u need some programmatic solution, try with this link:
How do you keep the machine awake?

Global hooks JAVA LINUX (Ubuntu)

I want to hook into another GUI app (probably using Qt).
I want to know, when some button is ready to click and etc.
My app technology is JAVA, my OS is Ubuntu.
Michal.
I can't help you with the button thing, but the most commom way of interacting with other desktop applications if there is no public API is using the Robot class. With a Robot you have control over the cursor (point&click) as well as keyboard input.
Javadoc java.awt.Robot
I don't know which application you want to hook into, but some expose data and methods via DBUS. It would be less costly.
I seriously doubt you can do this. Especially from java. Unless the app you're trying to control has some public API, or can be controlled with dbus.
This sounds like a job for some native hack via either X11 apis or something from Qt.

Copying selected text to a Swing Java app?

My goal is assign a global hotkey (JIntellitype, JXGrabKey) that would pass an arbitrary selected text to a java app.
The initial plan is to utilize the java.awt.Robot to emulate Ctrl-C keypress and then get the value from clipboard.
Probably there's a more elegant solution?
EXAMPLE: Open Notepad, type in some text, select that text. Now, that text needs to be copied into a Java app.
I guess you want to implement a global input monitor, Java is not so straightforward to do the job. You may have to write an API hook and pack it in a DLL, then invoke it via JNI.
The Robot only sends events inside your JVM. I don't know of anything to send events out to the operating system. Though there is plenty of examples out there of making JNI calls to the windows API, it would then be platform specific.
I've gone with with Robot and that works just fine.

desktop word-capture

If you know babylon translation tool you'd know its word capture feature - when you right click on a word - it tanslates it (from a browser or any documtent).
I want to get the same tool - what program language should i use ?
The os i want to get it work on is win-xp and ubuntu. and I'm writing my program in java.
if it could happen from a java program it would be great.
thanks,
Adi.
You are facing two (IMHO) insurmountable challenges:
Windows and Linux use completely different mechanisms for displaying text on screen. Translating mouse positions into actual text is pretty darned difficult. This is hard even if you're targeting a single operating system.
Java apps generally run in a sandbox, i.e., they can't just go mucking around in the OS asking other windows to tell them what text is under the mouse, nor can they override the default right-click action windows they don't control.
A better UI approach would be something that uses the system clipboard, which I think is available to Java on all systems (I'm not a Java guy, I'm not sure). So, the user would copy a word in any window, perhaps hit some sort of global shortcut key (again, assuming you can assign one in a Java app), and the Java app could access the word in the clipboard and do what it needs to do.

How can I handle multiple mouse inputs in Java?

A friend of mine asked me to implement a blue and a red pointer to represent the inputs of two separate mice to expedite a mixing desk scenario for real time audio mixing. I'd love to, but as much as I think it is a great idea, I don't have a clue as to where to start looking for a possible solution.
Where should I start researching a viable method of implementing dual mouse inputs?
Look at jinput.
I have had multiple keyboards working with it, I am nearly certain it supports multiple mice too.
dont know about java.. but for C#/c++ you can try the
Microsoft Windows MultiPoint Software Development Kit
i've tried it on windows.. it works with 2 USB mice.
It depends on which operating system you intend to use.
On Windows, you can use:
CPNMouse - a driver+software combination, very flexible and allows to completely hide some of the mice from the operating system.
RawInput - an API provided by Windows XP only. You can use it to distinguish between two mouse inputs, draw the cursors yourself and hide the main cursor. Take a look at the code of SDGT, a C# usage of this API.
For both solutions you would have to build a JNI bridge to your application
If you are using X.Org (X11) server, there is patched version called MPX that should support multiple mice even for legacy applications. It should now be a part of the X.Org trunk, but I'm not very familiar with it. Anyway it has an API so you can use it via JNI bridge.
You can use multiple devices, but at the Java level, all mouse events are coalesced into a single stream. The event does not include which mouse it came from. You did say you wanted to mix audio, right? Well this mix might be interesting, but surely not what you want.
I'd suggest using the Java-supported midi interface and connecting some simple midi controller device with multiple knobs or trackballs. These will come in as midi events, and you can examine the state for the details you need.

Categories

Resources