I'm addapting a IR TV controller to the computer. So far I managed to read the controller data, map the keys and assign a great number of functions using JAVA robot class and prompt commands.
I want now to create play/pause, stop volume+ and volume - functions. Problem is it can't be done diretly through java. I know the right way to do it is by using JNI, but I just don't have the time to learn it right now.
The solution I found is to create exe files containing only the SendMessage function. For example, the code por the Play/Pase function would be:
#include <windows.h>
#define WM_APP_COMMAND 0x319
#define PLAY_PAUSE 0xE0000
int main() {
SendMessage((HWND)(~0), WM_APP_COMMAND, 0, PLAY_PAUSE);
return 0;
}
The program works, but instead of sending only one single message it keeps sending non-stop.
I have to question. The first, of course, is why the code is not working properly. Is there a break comand missing or something?.
Second is what does assigning ~0 (or 0xFFFF) to the windows handler means.
Thanks, i'm open to any kind of solution.
MSDN SendMesage:
If this parameter is HWND_BROADCAST ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
Broadcasting with SendMessage synchronously sends to all those windows. How this message is handled is app-dependent.
Yes - this approach is as risky as it sounds. Can you find another way to do what you want without HWND_BROADCAST ?
Rgds,
Martin
Ive come across the same problem trying to write a java webserver to control my media PC running mediaportal using only a web browser on the local network as the client but I'm limited to what is in the java.robot class only.
I think the idea of using an exe called from Java is the right one, maybe look at a program that does all the messages instead of having individual exe files.
I think this might be like what you are looking for:
http://wiki.team-mediaportal.com/index.php?title=1_MEDIAPORTAL_1/17_Extensions/System_%26_Utilities/SendMessage
~0 is HWND_BROADCAST. The message is sent to all top-level windows in the system. This program sends the message exactly once. Possibly the program is executed many times, or message is handled in multiple windows.
Use Spy++ to investigate this. Spy++ is part of Microsoft SDK and Visual Studio.
Related
I'm trying to write a program that would send a function to several nodes, those nodes will receive the function and execute it, replying a result (through serialization). I've searched around a bit, but found nothing of help. An alternative might be to send a .class file over the socket and load it on the node, but i'm interested if anyone has found a simpler way
Edit: I'm trying to make a cluster with this client/server. And I want the client to always run on the nodes and accept any kind of work without having to recompile the client node code
Solution: seems there's no way around not sending a .class file. Have to send it, then load it at runtime
Java is not like some (mostly interpreted) languages where code is data. In order to do what you want with java source code, you would have to send the source code over the wire, compile it to a class file at the other end, and then load the class file. Apart from loading a class file, there is no other way to get new code into a running JVM.
P.S.: Opening up a port on your machine where you accept arbitrary code, and then execute whatever the client sends to you is like owning a Jewelry store, and leaving it un-locked and un-staffed every day when you go out for lunch.
P.P.S.: You could embed an interpreter in your application. E.g., you could embed JRuby, and then the client could send you Ruby code.
Try Hadoop Map/Reduce Framework:
http://hadoop.apache.org/docs/r1.2.1/mapred_tutorial.html
I'm trying to find a developer to write a desktop program that has a pretty basic function. It will notify users, via some dialog (or alert) that some program is about to access the web cam. It could be skype or facetime, or whatever it is, the program should be aware of when the OS's camera is going to be accessed and notify the user. Yes, even if the user is initiating the camera themselves via Skype, the notification would still appear.
My question is this. If I need this program written in Java, is it possible? Obviously I am trying to get it done in Java so it would run on Windows and Mac.
If it is not possible, then it seems as though I'd have to write 2 separate programs on Windows and Mac.
I've come here to get suggestions so that I can connect with the right developers. If you have any suggestions, I'd be happy to hear them. Thanks!
No, you can't write this in Java. Whatever approach you take will be very system-specific (and will probably require enhanced privileges). You could write a JNI library and a Java interface, but it'd probably be about the same amount of trouble to write programs to the native UI libraries.
Ultimately I would like to use a Java program to send and receive messages from a phone that I have plugged in via USB. I can do this using a C# program, however the program I want to send and receive messages is written in Java. To do this I am using the Rxtx library (but using the Windows x64 compiled version from Cloudhopper). But whenever I try and send any commands to the phone via USB my computer completely locks up and I have to hard-restart it.
The code I am running is here: Two way communication with the serial port. I think that it successfully establishes a link since it gets to the stage where it accepts input from the console, though when I press enter, and the input is sent, the computer locks up.
I am running Windows 7 x64, using Eclipse. Thank you for any help.
A little hard to tell from the code, but here are some debugging tips:
Try stepping through the code with the debugger line by line, and step in to the library itself to see if you can find the problem.
Instead of reading/writing from the console, try sending character codes programmatically. The console operates very differently from direct access. i.e. instead of System.in.read()) just try passing in a known good String.
Keep in mind that Java works with UCS-16 internally, but that consoles typically work with different character encodings (e.g. cp1252 for Windows). So, your "enter" may be a completely different character from what the system is expecting. If your device is expecting ASCII 13 and your keyboard is generating ASCII 12, that could be enough to confuse things.
The crash makes it seem very likely that there is something going on with the native library. If you find that the Java debugging keeps dropping you into the JNI boundary, you may need to debug with a C/C++ toolset.
Good luck!
I am writing a console application in Java. It is similar to a chat client: Input and output are asynchronously made. The problem is that if some output is made while the user is in the middle of typing, the lines will get mixed up on the screen.
I am looking for a solution which allows me to have a input area separate from the output area. At the moment I am using an extra thread which polls a BufferedReader on System.in.
The program needs to run on a Linux server and be accessed via an ssh session. So any hints that only work in this environment are fine.
Are there any high level libraries which can do this? Or is there a smart trick using terminal / ANSI codes? The ANSI codes s (save cursor) and r (restore cursor) might be helpful but how do i know where to jump to do the output and how do i handle scrolling?
I recall a long time ago working with similar things but in C++. I was using the ncurses library then. Check out javacurses which seems to be a Java implementation of something like ncurses.
Sounds like you need to use Curses. JCurses is a Java implementation of the Curses library and will give you control of the terminal to allow scrolling, positioning etc.
I'm interested in knowing how can my Java program listen to the Print event generated by the underlying OS. As my project is based on Java, the Print job event listener should not be platform depended.
To be more specific my program will be running on the background and should be notified of the print job if a user is trying to print pages from MS Word (for an example). The event should notify not only the print job being started but also other details such as No. of pages, the document location etc (if that's possible). A link to complete tutorial or some snippets would be much appreciated. Thanks!
We are a C++ and Java shop. I have written code that does pretty much what you are asking for. It was written in C++ for Win32 (and was a right bugger to get correct - this is one of the least well documented areas of the Win32 API - and different printers send different event streams, so it can be really tough to develop robust print queue handling).
If someone has created a JNI library for doing this stuff (unlikely), there is no way it will be cross-platform. The effort involved would be enormous (different OSes handle print queues and notifications in completely different ways).
My recommendation would be to brush up on your Win32 programming (with C/C++). Once you have things working there, if you absolutely must have them interact with your Java app, you can use JNI to wrap it.
Here's MSDN articles on printer change notification monitoring (you'll have to call OpenPrinter first - but the next call is FindFirstPrinterChangeNotification): http://msdn.microsoft.com/en-us/library/dd162722(VS.85).aspx
If you are trying to support *nix and mac as well, you'll need to dig for those separately. Good luck.