Maybe I wasn't searching the right key words, but I couldn't find anything on printing to another application's dialogue box. Most of my searches came to filling a web page, but I want to print a string to dialogue boxes of other applications like you would for logging into game launchers.
The operating system will usually not allow you to write into the memory of other application. So if the other application is unwilling to take your input, it's practically not possible.
If it is willing to take your input, there are several ways:
Accepting input through the standard input - This means you need to open it as a process and write into the output pipe
Having an open web API - the application is listening on a network port and accepting connections (e.g. HTTP) so you can send HTTP requests to it (even from the same machine)
Listening for any other inter-process communication method - either subscribed to a broker you can publish on, or directly listening for connections (let's say on UNIX-domain socket).
If the application is not listening to anything, nor using any shared resource/memory piece, then there's effectively no way.
Unless...
You wrap the application up in an application of yours. The same way the most game launchers and even game cheats do. Then your application will be completely responsible to proxy the output of the other application to the end-user. Your can take its output, augment it a little bit (e.g. add some texts to a rectangle) and then render it to the user.
Related
i'm stuck at capturing keyboard events.
I'm working with a barcode scanner which is detected by system as traditional keyboard (it is it's only mode, my client has a lot of budget scanners which can't emulate virtual com port).
My goal is to be able to detect at which port is this scanner plugged in, capture any input from that port, and prevent it from being handled by the OS (i don't want the barcode numbers popping up on focused input).
All this must be performed by a background service, which is never an active window, AND the solution must work both on linux and on windows.
I've been able to capture the input using jnativehook, but failed to prevent it from being handled by OS.
As far as i know, it is impossible to achieve this using pure java (JVM gives access to keyboard events only when application window is focused), so how should i handle this issue? I'm okay with using jni and c++ if that's necessary, but i don't know where to start.
JNativeHook does have the ability to discard events on Windows and OSX (not Linux), however, it does not have the ability to determine which USB port the scanner is connected to. The reason it cannot consume events on Linux is because the XRecord API makes a copy of the events and doesn't sit directly on the input event loop. If the devices you are working with can utilize HID, I would take a look into some of the JNI HID library wrappers like gary-rowe/hid4java or signal11/hidapi. The assertion that "it is impossible to achieve this using pure java" is correct. The only way to do it would be though native code, and HID is the most appropriate native method to accomplish your goals. Other input methods like input hooking (used by JNativeHook) will not be able to provide you with the source USB port, nor can they consume events on some platforms (Linux). There is another option out there like melloware/jintellitype that use a different mechanism for capturing input. I don't think it can grab input based on the port, however, the non-portable Linux equivalent of this library uses the XGrab API which will only consume events, but again, I don't know if it will be practical for your input source as I think it can only bind one key per call and that key must use a modifier.
Hope this helps you move forward with your project.
I have a program made in Java, which you want to configure as an operating system service. The program reads data received by socket, which processes and stores it. It also logs errors and finally prints the information flow all the time in console to observe its operation.
After setting it up as a service, a need arose.
How do I view the print activity in console, if the application is in the background and therefore the console is not open?
Is there a way to view the console output of that application?
It occurred to me, if it is possible to create another Java application to read and print the console output of the created service. Would that solve the problem?
Thank you very much for your comments, after researching a little more thoroughly, according to your suggestions, i developed an IPC communication system via Sockets, in which, an swing application connects to the service and requests Every 2 seconds the required information and the sample in the app
If I have a random program, that shows some text and has some text input, is there a way to write a java program, that reads that text labels and/or fill that text input fields and press an ok button?
Text applications are things that run on the cli, and have no windows. On Microsoft Windows the 'dir' command is an example.
Graphical applications are things that the beginning user might see, and has buttons, text boxes, scroll bars and stuff like that. On Microsoft Windows the 'paint' program is an example.
Web applications are websites that provide front ends as web pages. The 'gmail' application is an example.
If you want to interact with an application using Java, the application type will determine your approach.
text application - use ProcessBuilder, it's a java class designed to launch and (to a degree) interact with processes through stdin, stderr, and stdout.
Graphical application - It depends on the graphical widgets the application uses. If those are not supported by a library that can navigate the presentation, then input is limited to x,y coordinates from the application's origin, and input could fail to go into the right component.
Web applications - Use selenium. It is a custom web browser solution that permits testing of web sites; but, you could use it for your task. It is big and complicated, but considering what is required for this task, it is comparatively easy to use.
Yes you can write a new program that can give input and trigger the service of 'OK' key.
Your first program needs to be designed in the way that - it should accept the input from second program.
You can design the first code as web service in a web application . your first program will be web service provider and second program will be web service consumer.
Using second program you can post the required data to first code. and all the triggers of 'OK' button can be processed from first application.
I've a generic design question. Hope you folks can help me. Our technology stack is Java, Angular, Spring and REST. We wish to implement a reservation system (to reserve machines/servers) so that if one user wishes to ssh to a machine then they first reserve it one our UI and then they only can use it and no-one else can.
Do you guys know a way/technology/design where we could control access to machines this way (possibly something like LDAP) ?. Even something where the user logs into our UI, reserves the box by clicking a Reserve button etc and then clicks a Launch button - which could then launch an actual ssh command window or a remote desktop access session etc. In this way we could set a certain predefined username+password for our boxes (which our application could control) and we can allow users to connect to boxes via our UI.
Wondering if any one you had to do anything similiar to this before or if there is anything obvious I'm missing. Is it easy to "launch" a remote desktop connection or indeed an ssh terminal from java.
I'm fine with the UI part, rest, java etc. It's more the connections / logic to the remote machines that I'd like to get peoples thoughts on.
Sorry if this is too generic. I'd like to get some directions on it.
Any thoughts/guidance would be great.
Thanks - Ro
I am looking for an addition for our "livestream and podcast" solution, which uses a camera to film speeches in our house.
It has been requested to view the slides of our speakers directly as a image in the webbrowser instead of the video stream. We don't want/can not install software on the speakers laptop, so I thought about a Java applet, which the speaker can just run via a webbrowser.
So what I need is technically this:
[speakers laptop] -> [Screencapture every N seconds via applet on a webpage] -> [Displaying the screen of the speaker on a different webpage for the external viewers]
I know there are Java applications which do record the screen, but save the file output locally. I need something that does the same, but sends the image to the server. On the server side I thought about a websocket.js accepting and displaying the image (other suggestions are welcome).
It would be great if somebody could help me out here. Btw, I never programmed in Java, so telling me which frameworks I need won't really help me.
Thanks!!
I was recently asked to evaluate possibilities for live screen-cast via applet. Most video APIs do not support codecs that have high enough compression (e.g. JMF). Some APIs can do advanced formats (JFFMPEG, Xuggle) but also use natives. While natives are normally no problem for an app. launched (free floating) using Java Web Start or a Plug-In 2 applet, the makers of Xuggle identify 'the order of loading natives' as a problem (e.g. won't work) for both JWS and applets.
It is a pity that more than a decade into its development, Java has no reasonable API for video capture/processing that can be deployed for a wide use (applet/JWS based - for the 'general public') GUI.
Perhaps you can find a solution using Flash.
Update 1
In fact, I do not need the screen to be recorded as a video.
In fact, you mentioned much of that in your initial question, but I focused on just a few keywords before drafting a reply. My bad. :P
OK.
Getting an image is relatively easy. An applet would need to be trusted in order to get a screenshot, but once trusted, it is just a few lines of code to get the image.
Encoding the image to JPEG of particular quality/compression setting (in memory) is also doable.
Sending the image to the server would depend on the size in bytes and connection speed, but one image with a high compression, every 10 seconds, should be doable. The server would need to implement functionality to accept the image.
As far as displaying the image on the client, it seems you already have some ideas based around JS. If you can make that work that would be optimal, since it can then be viewed in browsers with no Java.
I would still recommend you deploy the app. to the 'speaker' using Java Web Start, rather than embed an applet. A JWS app. will give you less deployment & maintenance troubles, and the JWS launch is ..nicer. Further, a free floating frame launched using JWS can minimize itself (or in later JREs, become transparent), during the action of taking a screen image - thereby capturing everything on the screen except itself.
Update 2
I actually found this code here.
That is ..horrible. Not the code, the site. When I visited it I got a message saying a pop-up had been suppressed (fair enough). Then there was the irritating 'vibrating dialog' hovering in the middle of the page (and following the scroll). You click the little x to see - another tab opened with yet another floating dialog, saying some other rubbish about how "You've won.." - with sound loud enough to drown out my high volume trance/dance playlist.
Then after closing that the hell out of my FF, I go back to the original page, close the damn 'dialog', scroll down & see.. a red background to the code (shudder). That is as far as I could manage. I closed the page with the code.
Try this code instead, for a single screen-shot.
Would it be possible to use this on the client side..
Yes.
.. and receive it with javascript on the server side?
Not really. Unless you mean an IIS based server running Microsoft's JScript. JavaScript is a client side technology.
For security reasons, servers need to protect themselves. E.G. From:
Someone creating a slavebot that uploads all the 1000s of docs on the slave machine's to the site - to make it crash.
People high-jacking your server for storing and serving bestiality porn (or worse).
Because of things like that (bad people have lots of imagination), while servers can easily accept uploads, they are generally not configured by default to allow them.
.. (I don't want Java on my server ;-)
It can be done using PHP, ASP, CGI etc. It does not need Java specifically, but it does need some active involvement from the server, if only to check the size of what is being uploaded and abort if it gets too large!
..Will take a look at the link you posted, but as I said, I can't program in Java, though I can understand some of it. Thanks!
It sounds like you'll need some help getting the server-side of it ready, as well. It is trivial for someone that knows how (not me), but a potential security nightmare for the inexperienced.
Update 3
where do I add the function to send the picture?
Sorry. I've not tried to implement that - you'd want to want to encode it to JPEG before sending, to reduce the size. See this code for how to provide an adjustable compression/quality where the user can see the effect.
There are various ways to get an image to a server. E.G. sockets, HTTP, FTP.. AFAIU it would depend on how the server is accepting it. I am unfamiliar with the specific term 'websocket' or the node.js script. Can you link to what you mean?
..the old code added to pastebin, so it's readable
Smart thinking. I notice it uses sockets, it was in the back of my mind that sockets would be best for this, since they have low overhead and short wait times.