I’d like to write a simple program that reads a barcode, and makes a note of the barcode as well as the time it was scanned in. Unfortunately I cannot guarantee that the program will have focus when the code is scanned. My understanding is that most barcode scanners act like a keyboard so if the program does not have focus I will have issues. What are the ways to deal with this? Note I’d prefer to code this in Java but I can use .net if the libraries make it easier. I also don’t have a specific scanner in mind so if one model will work better for this that info would be appreciated. I’ve sceen this question but it assumes the app has focus.
Most barcode scanners behave like a keyboard, hence requiring the processing application to have input focus. There are however also barcode scanners, which connect to the serial port or are connected to the USB and offer a virtual serial port interface.
These scanners must be accessed through the real or virtual serial port. For Java, you will need to use the Java Communications API or any other 3rd party library offering access to the serial ports, since this is not possible with the standard Java API.
Most keyboard wedge barcode scanners can be configured (via configuration barcodes) to emulate a keypress of a function key before sending the barcode data. The Windows API includes a RegisterHotkey function to define system-wide hotkeys. When the hotkey is pressed, you could give focus to your program's window to read the barcode.
A Google search reveals a library to register system-wide hotkeys from Java. There's also a question on this site about it, which seems to suggest that there isn't a publicly available library to do so in Mac OS X, though one of the answerers posted a link to such a library he was developing.
After some research on this I implemented as jarnbjo mentioned with a virtual serial port, an example is here (see my answer).
Related
I have in hands the creation of a Warehouse management system. It's going to be a web application, it's supposed to run on desktops and 10' tablets.
I have never worked with barcode scanners, so my question is how do I interface a barcode scanner with my application?
It's going to be a Java EE 6 application, the web framework to use is still open.
Any experience with similar setups would be greatly appreciated.
Like Alex K. says, most scanners act like keyboards. So handling the input shouldn't be difficult.
I have seen this type of system implemented with an ActiveX control (Ewwww), but I'm assuming you would want this app to be cross-browser.
Java in the browser is as good as dead now, so an applet would most likely be out of the question.
If the scanner sends a key first you could easily bind an event listener using JavaScript to wait for that key and then take the input.
I want to use a program written in a high level language like Java or Python to talk to a GSM Modem.
I want to be able to tell the modem what number to call and when to call it. I also want to be able to read and send text messages.
I do NOT need to handle voice transmission in either direction of the call.
I'd appreciate recommendations of any applicable libraries and specific modems that are good to start with? I like Java but am willing to try something else.
Thanks
There are a set of relatively standard "AT" commands that can be used for these types of operations - including placing phone calls and sending text messages. Some details around this are at http://www.smssolutions.net/tutorials/gsm/sendsmsat/ and http://www.dreamfabric.com/sms/ (simply first results of a little online searching).
A little more online searching yielded a Java-specific example at http://www.java-samples.com/showtutorial.php?tutorialid=22 .
I had done a little bit of this in Java a number of years back, using the Java Communications API - available at http://www.oracle.com/technetwork/java/index-jsp-141752.html . (My purpose was for interfacing with the phone book on my phone, but this also should have worked with interfacing with the SMS system.)
Almost all modems and (phones which support tethering to your PC) can do this. All modems are equally good at it.There are no starter's modems. Just go through the AT commands specific to your applications and thats it.
Im making an application that should see if your online or away.
So i need to somehow see when the user hit a key on the keyboard last time.
The application is running in the background and you can only access it from the trey.
Is this possible and if it is how would i check.
Best regards
I believe that what you're looking for can be done via a global keyboard hook, but that doesn't have direct support in the JVM. From Googling, it would appear that your only options are to write a C++ shim which you can use via JNI, or go via libffi with JRuby.
From what I've read here it is not possible to add KeyListener to the SystemTray. The only listener that is supported, is the PropertyChangedListener.
Furthermore from that question it seems to be possible on Windows but not on Linux and MacOS.
This is possible, but not using Java. You'll have to use JNI to access OS APIs that provide this information (and implent it differently for each OS).
I would like to write a program which can monitor activity of my keyboard. In more details, the Java program should "see" which key is pressed/released and when. All this information should be stored in a given file.
First of all I would like to know if it's possible to do it with Java. I know that it's possible if I type in a text field generated by Java program. But is it possible for Java to monitor the keyboard activity if I type, let say, in a text field of a browser or, for example, in word (or open office) document?
These events are directed to the window which has the focus, from all events on the desktop you can only get the mouse position.
import java.awt.MouseInfo;
public class Mouse {
public static void main(String[] args) {
while ( true ) {
System.out.println( MouseInfo.getPointerInfo().getLocation() );
}
}
}
For capturing sysem wide (what you need for word) you need to include a native lib
Code example for windows: Native keyboard mouse hook
Forget JNI and JNA.
There is now a new library for native mouse&keyboard access that works exactly the same as MouseXxxListener and KeyListener. In other words, it's a familiar interface so you don't have to learn anything new (except for how you link an external library).
https://code.google.com/p/jnativehook/
Forget JNI
JNA is the solution (is based on JNI but it's way easier although most people don't use it thinking it's as difficult as JNI, but it's not)
Check https://github.com/twall/jna/
and specifically in the middle of the page where it says: Platform / Platform Documentation
If you download the platform.jar (and check the sourcecode) you'll find a wrapper around
User32.dll where you can find the win32 function
GetAsyncKeyState(int vKey)
mapped to a corresponding java function
(see h**ps://jna.dev.java.net/javadoc/platform/com/sun/jna/platform/win32/User32.html)
There u can check the state of a key (pressed or released)
If you need a global key listener have a look at my other reply to:
h**p://stackoverflow.com/questions/696170/java-keylistener-without-window-being-open/4394398
Thanks to Stackoverflow i can't post more than one working link in my replies :(
Cheers
It's likely possible to write a Java-based key logger using some native libraries, although be aware that such a program is likely more noticeable than one with a different technology, since the Java VM will need to be running for it to work. Keep that in mind if you're trying to be clandestine.
Also, if you just need such a program for use, and don't have to develop it yourself, there are many hardware and software keylogging systems already out there that you could use instead.
I think that native functions can do it.
It's something like you can connect c++ with Java.
http://en.wikipedia.org/wiki/Java_Native_Interface
What you are requesting is not possible using the Java API. In order to do system-wide key logging you need to register with win32 (or other OS native) hooks. Specifically, this will be done using native libraries and interfacing with the JNI.
There are some code snippets over at http://forums.sun.com/thread.jspa?messageID=3808163#3808163. It's a good example of how to get started with JNI and registering a Java callback to a win32 hook.
I would like to capture key strokes and mouse events being entered into a different window, eg such as a browser. What is the best approach to doing this, and no i dont want to be sneaky and capture bank account passwords.
I appreciate that this requires JNI in order to setup some hooks and the like with the current host OS. I could not find any premade java library that had this facility which is odd given that Java has libraries for everything.
This kind of job is OS dependent and there is no cross-platform way to do it with Java.