how to record keystrokes in background using java? - java

I am going to research on which key typed most in which hour in a 24-hour-day?
Later, I would research on which word used most in which hour in a 24-hour-day?
Say in the evening you would find most used word good or bye as people usually ends up their meeting in the evening.
So, I need to record keystrokes on the background using a java application with a time-stamp.
My questions are:
How to run a java program on the background?(Obviously informing the user).
How to record keystrokes which are used in other applications and counted in the java application without affecting its original application?
Note that:
This question does not serve my problem. Though it has an accepted answer, but the answer is not helpful for me because it could not distinguish between uppercase and lowercase letter, it returns same ASCII character. It just gave some sources and some other files. I expect more readable answer and a clear view how the java program launch on the start up and run on the background.

Just a little information to get you moving in the right direction. What you are looking to implement to listen for the keystrokes is KeyListener. I believe the actual function is keyTyped(ActionEvent e) but am not sure.
Other then that to run a program silently in the background will probably require some manipulation of the window + windows properties. You could just have the program run without a UI, or create a very lightweight UI that posts data. If you are looking for an actual "out of sight out of mind" background process, I am not sure how to do this with Java. However I imagine just an un-intrusive GUI would be sufficient for your purposes.

Related

How do you grab a certain string of text through a link in java?

Is it possible to grab a certain piece of text through Java in a website? like for example, https://weather.com/weather/today/l/41.93,-88.25?par=google&temp=f , how would i be able to figure out the temp that it displays in java?
The practical answer to your question is: You don't wanna do that.
Let me try to answer it, at which point you'll realize why you don't want to:
How do I programatically parse a website?
It's complicated. Just about every browser has an option to right click and 'view source'. Presumably the number(s) you want are in here; you can parse this text to find them. It's NOT easy though. You'll probably be tempted to use something like a regular expression or a simple 'find me this exact string of text' trick to find what you need. It may work. But generally that means the day that this site changes the style or just does some basic updates, your code ceases to work.
You'll need to put in your agenda to check, every day if you have to, if your code still works. That's 5 minutes out of your day, every day, for the rest of the life of this project. That sounds incredulously expensive, which is why you don't want this.
If you must, there are ways to tighten up your parsing code. If you use libraries like jsoup, that helps a bit. If you toss the entire site through a 'browser emulator', you can deal with javascript making ajax requests and the like (these days websites are like little programs, and to truly observe programmatically what the site shows to human eyes, you need to run that program to get the job done. If you're very lucky, you can inspect the 'source code' of the little program and that's all you need, but you're not always that lucky).
But, as I said, that just helps a bit. The day will come the weather channel changes their site and breaks your code. They won't announce it. It is not considered immoral or technically dubious to do so. Maybe you can update your agenda to check if your code works down to once a week instead of daily, but it'll be a permanent maintenance burden. You DO NOT WANT THIS.
Okay, forget that. How does this really work?
Sites that are designed to let you read this stuff have an API. They'll document it someplace. This is a 'website' made specifically for code. It has no formatting, and a well defined specification. Send it this specific simple string, and this specific simple answer comes out, and the site has tooling to let you know when they change it (for example, an 'API version') - all luxuries the site meant for human consumption will not have.
You're in luck. The weather channel has an API.
What you really want, is to read all that, figure out how that API works, and use that.
The API will not break when the weather channel decides that today is a good day to slightly change the shade of the background image.

Barcode scanning into Swing textfield sometimes swaps characters

We see an extremly weird behaviour with barcode scanners and a Java Swing application on Windows 7 and jre8. This is a large deployment of more than 1000 PCs and several different barcode models. We scan barcodes that represent strings with 9 characters: H06AVKTI2
Now "sometimes on some installations" some of the later characters appear in the wrong order:
H06AVKTI2
H06AVKI2T
H06AVKTI2
When we scan into notepad or an outlook email, we never see the problem, only in our Swing app.
it only happens with the 3-4 last characters of the string, the first 4-5 are always correct.
It happens with most/all barcode scanner models and PCs, but on some installations never, on others often - no pattern so far...
It is nowhere 100% reproducible - just on some PCs it happens often (more than 50% of scans are wrong)
When we started two instances of our application on the same PC we saw it happen in one instance very often but never in the other.
It does not seem to relate to the specific scanner model, barcode, user or installation
there is no network traffic when we type into this field, hit enter or any other key when this field is focused - we checked with Wireshark.
Any idea is welcome - we are desperate ;-)
We eventually solved this. Turns out that this Java Swing application allows to configure keyboard shortcuts that are available to execute certain business tasks under certain conditions. Somebody had globally configured shift-t and some other shift-_ to be shortcuts for business transactions.
Now even though these business transactions were not available in the context when we scan barcodes, the app seems to interupt for a few milliseconds whenever it receives a shift-t. When the barcode-scanner scans a code containing a "T", it sends one of these shift-t combinations and the software takes a very short time just to determine, that there is nothing to do for this shortcut. In these cases the scanned characters end up being swapped. So this obviously only happend when we scanned a code containing one of the characters we had configured shortcuts for...
Solution was to change the configured shortcuts to ctrl-t instead of shift-t.
Root cause is probably the way the framework developers of the app implemented those global shortcuts, but this has not been verified.

Can you change a line after you've outputted it with System.out.println?

I have been coding for a while now and as far as I'm aware, once you've outputted a line to System.out.println in Java; you cannot change it.
The reason I ask this question is because of some very strange results from my program. The program records the time of the bubble sort and merge sort algorithms in sorting different kinds of int arrays and prints the average of these times at different sizes of n, where n is the size of the array.
Now I've had a litany of problems with this program thus far, but I do not understand how the following is possible:
...
At 200000, randomly-sorted takes:
NaN //Expected output, since I did not activate the random arrays.
...
However, at the same line, and in an unpredictable manner, the program occasionally does this:
...
At 200000, randomly-sorted takes:
75683.45
...
And then swaps back again after a while!
So the program is somehow managing to replace the outputted line, which I have never experienced before.
Any help or clarification very much appreciated! If you need the code, I am more than happy to share.
EDIT: To clarify, this is on a Macbook Air running Java SE 6. As for the code, please refer to my Github account with the entire project at the following link - https://github.com/danielsoutar/complexityPractical.
Side-note: One other thing. For bubble sort, the randomly-generated arrays apparently take longer to sort than a reverse-sorted array, which is clearly nonsense. Not sure if that matters to this problem but it is something to note.
the question was kinda unclear to me, but as far as I understand you could take a look at RegEx for filtering out on a String or clear the Console and put your output back in.
Clear console:
Runtime.getRuntime().exec("cls");
RegEx example:
yourString.replaceAll("[yourCharactersToReplace]","");
System.out refers to a PrintStream instance. In the abstract, a PrintStream object represents a place where you can send text. Period. Once the text is sent, that's the end of the story.
But in reality the text actually goes somewhere. If you are invoking your Java program from a command line, then it's very likely that the place where the text goes is a terminal emulator window or a console window; and it's also very likely that the console recognizes certain codes that your program can embed in the text that tell it to do things.
Things like, change the color of the text, move the cursor around in the window, and over-write text that already was there.
There have been literally hundreds of different coding systems to let a computer program do those things on a terminal screen/window, but one is supported by almost all consoles and terminal emulators. Google for "ANSI escape codes" to learn more about it.
If you want your program to purposefully move the cursor around, change the text color, etc. Then you might want to use a 3rd party library like jcurses (google for that too) to handle the possibility of a console that does not accept (or is not configured to accept) ANSI escape codes.

Is it possible to modify the time OSCeleton sends a lost_user event/message?

I'm playing around with OSCeleton and Processing and succesfully got to track skeletons and do stuff.
What I'm wondering is if there's any way to change the delay time a "lost_user" message is sent to Processing.
This is taking so long for what I'm trying to achive, since i need to stop tracking a user as soon as he goes away from the screen, so I can accept another user's interaction. (imagine an installation where a lot of people wants to play with).
any help/tips would be really appreciated.
Jon
As far as I can tell from the OSCeleton's source and with my minimal experience with the kinect(I never used OSCeleton), there is no way to modify that code to do that. It seems to be a thing handled even lower, by the driver or by the kinect its self(?).
Yet you need not bind yourself with that, and I would suggest a couple of ways to bypass the problem if I understand properly.
First, the latest drivers and examples should have multi-user support, meaning you can just arrange who is your main user. From what I can tell from the source you do get an osc message in Processing when a new user is detected as well as an ID number. You can put each new user that arrives, into an arrayList and figure out a way to do things without depending on the latest user.
If you are still going for the user-after-user thing though, or I was mistaken about the multi-user support(which is mentioned nowhere in the README), you can check yourself whether a user has left the area. Although you can not get a definitive answer like that you can check for example, whether a specific joint or all joints of a user have moved in the last 10-20 osc messages received. That probably means storing the position of this joint in an 10-20 item array and continuously updating while also doing a check on whether the items are different. If all items in the array are the same, your user has not moved a bit and thus probably should not be taken to account.
Last but not least you can switch to other solutions. The one I used about a year ago was "Synapse for Kinect" which also seems stale now. The latest you can use is a Processing library called SimpleOpenNI which definitively have multi-user tracking and you won't need any intermediary programs running to give you the joints.
I hope this helps

Parsing IBM 3270 data in java

I was wondering if anyone had experience retrieving data with the 3270 protocol. My understanding so far is:
Connection
I need to connect to an SNA server using telnet, issue a command and then some data will be returned. I'm not sure how this connection is made since I've read that a standard telnet connection won't work. I've also read that IBM have a library to help but not got as far as finding out any more about it.
Parsing
I had assumed that the data being returned would be a string of 1920 characters since the 3278 screen was 80x24 chars. I would simply need to parse these chars into the appropriate fields. The more I read about the 3270 protcol the less this seems to be the case - I read in the documentation provided with a trial of the Jagacy 3270 Java library that attributes were marked in the protocol with the char 'A' before the attribute and my understanding is that there are more chars denoting other factors such as whether fields are editable.
I'm reasonably sure my thinking has been too simplistic. Take an example like a screen containing a list of items - pressing a special key on one of the 24 visible rows drills down into more detailed information regarding that row.
Also it's been suggested to me that print commands can be issued. This has some positive implications - if the format of the string returned is not 1920 since it contains these characters such as 'A' denoting how users interact with the terminal, printing would eradicate these. Also it would stop having to page through lots of data. The flip side is I wouldn't know how to retrieve the data from the print command back to Java.
So..
I currently don't have access to the SNA server but have some screen shots of what the terminal will look like once I get a connection and was therefore going to start work on parsing. With so many assumptions and not a lot of idea on what the data will look like I feel really stumped. Does anyone have any knowledge of these systems that might help me back on track?
You've picked a ripper of a problem there. 3270 is a very complex protocol indeed. I wouldn't bother about trying to implement it, it's a fool's errand, and I'm speaking from painful personal experience. Try to find a TN3270 (Telnet 3270) client API.
This might not specifically answer your question, but...
If you are using Rational Developer for z/OS, your java code should be able to use the integrated HATS product to deal with the 3270 stream. It might not fit your project, but I thought I would mention it if all you are trying to do is some simple screen scraping, it makes things very easy.

Categories