How to read string from a field without pressing enter - database

I have a barcode scanner that needs to read data into a database whenever a barcode is scanned. All the scanner does is take the barcode and create a string with it. Barcodes, however can be variable lengths.
The idea behind it is to have a java class open, and the user will scan multiple barcodes one after the other (without pressing the enter key). This class must then take each barcode and read it into a database.
I need help to read the strings from the scanner without the user having to press enter each time (as this makes the program pretty useless and not very user friendly)
Thanks. Looking forward to finding a solution!

I've done something similar to this in .NET but the concept should be about the same.
I would set a timer up with a delay long enough to be a sign that input has stopped but not too long to cause delay - so say 500ms.
On text box update event you ensure both that the timer is enabled and that you reset the timer essentially giving you another 500ms to enter more information.
On the timer tick event or equivalent you do your action (in your case save to the DB) and disable the timer, ensuring you don't affect focus during the processing obviously.
Assuming you also clear the text box, you can then after whatever delay you specify scan something else and trigger the exact same functionality.
Note this may fall down if you ever have to fall back to using a keyboard instead of barcode scanning. At the very least if this was the case you would need to research a better delay value that would accommodate both or maybe provide a way to disable the timer and revert back to using the enter key
Hope this helps

Related

LabVIEW: Count how long a button has been pressed

I'm trying to create a LabVIEW VI with an "ok button", a numeric indicator "Number of click" and an array of cluster, in which every cluster contain a TimeStamp indicator and a numeric indicator.
When the VI is running I want to keep track of:
When the button is released (timestamp)
How long the button has been pressed (in millisecond or second).
Then, when i click on STOP, i want to visualize these information about ALL the button pression in the array of cluster.
That's what I've done. I've tried to change the manner in which I create the array, and also the "Tunnel mode" in the While loop, but it doesn't work..
Can you help me? Thank you all!
please check my attached code and compare it with yours.
It's the simplest method, but you may also read about Event Structure, which would help to do that in much smarter way. Additionally you may want to change my code a bit to have indicators being updated in real-time instead after the exit. It's worth also reading about "Feedback node" and "Conditional" type of output tunnels. They would help to simplify the code, but I didn't use them to keep it as simple as possible!

X11/Xlib: virtual keyboard input and keyboard mapping synchronization issue

For an automated test application I have to simulate large amount of unicode keyboard input into an old X11 application (of which I don't have any source access).
My program takes the input from an UCS-2 LE encoded input stream via stdin and the basic operation is as follows:
Save current keyboard layout and lock modifiers (XDisplayKeycodes, XGetKeyboardMapping, XkbGetState)
Unlock active modifiers (XkbLockModifiers)
Disable all X11 slave keyboard devices via Xinput2 extension
Read input into a key press queue until n unique symbols are encountered, where n is the number of possible keycodes as returned by XDisplayKeycodes.
Map these n unique X11 KeySyms via XChangeKeyboardMapping on the n available KeyCodes
Type the correct KeyCodes for all enqueued KeySyms via XTestFakeKeyEvent
Clear the queue and continue at 4.) until no input is available
Reactivate keyboards and restore initial modifiers and mappings
Basically this system works better and much more performant than any virtual X11 key input tool I've seen so far.
However, there is an issue I can currently only fix using ugly delays:
As any other X11 application, the target application receives a MappingNotify (request==Keyboard) event from the X server after my application succeeded in changing the keyboard mapping table.
The usual response of a X11 client is to call XRefreshKeyboardMapping to update Xlib's knowledge of the new keyboard layout.
Now if the the client has some lag processing its X11 event queue, the XRefreshKeyboardMapping call might return a too recent mapping that is already some generations too far in the future.
E.g. my input generator has already done the fourth XChangeKeyboardMapping when the target application just arrived at handling the second MappingNotify event in its XEvent queue handler.
Actually it should get the second generation of the map, which isn't available at the X server anymore at that time.
Unfortunately there is no map id or version of any kind in the keyboard MappingNotify event so that XRefreshKeyboardMapping could refer to a specific map ... and the X server does not seem to keep a history either.
The result is that the X11 application's KeyCode to KeySym conversion operates with an invalid layout and generates wrong KeySyms.
So basically I have to wait until all clients (or at least the one with the input focus) have requested and received my last XChangeKeyboardMapping map before I am allowed to do the next XChangeKeyboardMapping.
I can fix 99.9% of the errors using a delay before XChangeKeyboardMapping and that delay is calculated by some ugly witchcraft (amount of key strokes etc.) and is way to high if 100% accuracy has to be achieved.
So my question is if there is any way to programmatically be notified or to check if a X11 client has completed XRefreshKeyboardMapping or if its map is in sync with the server map?
If not, is there a way to get another X11 client's current mapping via xlib (to check if the map is current)?
Thanks for any hints!
I've done something similar on Windows in the past. I had the luxury of being able to use the SendInput function which accepts a KEYBDINPUT structure with KEYEVENTF_UNICODE flag. Unfortunately X11 does not support direct keystroke synthesizing of Unicode characters.
Since I cannot comment yet I'm forced to give a suggestion as answer:
Have you considered using the clipboard instead in order to transfer your "unicode input" into this X11 application's input field ?
You also might consider using direct Unicode input if that application uses a toolkit that supports this:
E.g. programs based on GTK+ (that includes all GNOME applications) support Unicode input.
Hold Ctrl + Shift and type u followed by the Unicode hex digits and release Ctrl and Shift again.
I guess it should be easy to synthesize these sequences using the Xtest extension.

Saving form data as user types (React/Postgres)

Given a simple textbox to answer a question, how would you go about saving answers as the user types? Assuming that the answer is upserted.
Using a somewhat naive example of an onChange handler and saving answers using an API within that onChange, I ran into two problems:
Sends what seems to be too many patch requests from client to API since it's every time the input textbox answer changes.
If using postgres upsert or creating your own, then the second request made by the onChange handler may not see the first if the user is typing quickly, creating duplicate records for that textbox (two answers for one question)
I need to execute queries beforehand to get necessary relationship values before updating, so the HTTP wait time is fairly long. Fixing this now, but seems to not address the above two issues.
I thought of only saving once the user presses spacebar, but that seems hacky. Normally of course I'd save after clicking a submit button, but in this case it must be as the user types.
Any suggestions / comments? Cheers.
EDIT:
Also tried saving within onBlur.. But this doesn't always get called depending on where the user clicks.
Does it have to patch the data for every keypress or can you use a delay?
For instance...
User starts typing: Register the event, set a timeout for say 3 seconds
If the user keeps typing: reset that timeout back to the full 3s
If the user pauses typing + 3s passes: patch the data with new value
When the user resumes typing: set another timeout

How to detect when text is replaced in GtkTextBuffer instead of delete followed by insert?

I have worked a great deal with the text system in Objective-C for macOS/iOS (e.g. NSTextView, NSTextStorage, etc.) I am now experimenting with GTK3 to see how well I can translate my project for use on Linux, etc.
I am brand new to using GTK, but after a few days of Google time and experimenting, I have a working text editor prototype with my custom code plugged in.
The problem is this -- I need to be able to detect when a user highlights a section of text, and then replaces it with other text (e.g. a keystroke). This is distinct from highlighting a section of text, hitting the delete key, and then typing the new text. A specific use example would be highlighting a word, then typing a double quote character in order to wrap the word in quotes (e.g. foo becomes "foo").
In Cocoa, one would receive replaceCharactersInRange: that indicates the range originally selected, as well as the new string to replace it with. I can then detect the presumed intent of the user based on the information received.
In GTK, it seems that we receive a delete-range signal, followed by a separate insert-text signal. Because of this separation, the code in the "insert" section has no way of knowing that the user intended to replace text, not insert new text.
I used the following to receive the signals above:
g_signal_connect(buffer, "insert-text", G_CALLBACK(insert_text_cb), NULL);
g_signal_connect(buffer, "delete-range", G_CALLBACK(delete_range_cb), NULL);
Is there something else I can do in order to tell that there is a delete, followed by an insert as part of the same user action?
Thanks for any pointers offered!
Instead of trying to correlate the delete and insert events, I would suggest creating a GAction for your desired action (e.g. toggle quotes around the selected text) and setting its shortcut key to " using gtk_application_set_accels_for_action().
For more information, check out this HowDoI wiki page.
No answers over the last month, so I kept brainstorming and digging around. I finally came up with this, which works, but is not quite as elegant as I had hoped.
Handle delete-range signal as before, but keep track of the the deleted text for later (e.g. in char * deletedText).
Handle the insert-text signal as before, but if we have a string in deletedText then change the behavior to perform a replacement instead of an insertion. In my case, this actually meant inserting the deleted text back in, and then performing the replacement.
Add a callback for the end-user-action signal, which indicates that all delete/inserts associated with a particular action are complete. In this callback, free deletedText from above and set to NULL (to indicate that everything has been handled).
Again -- this works, but feels a bit inelegant. And depending on how complex your delete/insert routines are, it may slow the performance slightly since some steps have to be duplicated. A better solution would be to detect during the delete-range callback that there is a pending insert-text callback and handle both steps at once. I have thus far not been able to do that.

Multiple IR Key Press Events

I'm currently working on an IR key handler for a box running on linux kernel 2.6.15. I'm fetching IR key events from tts/1. The issue I'm facing is that for a single key press on the remote results in 2-3 key press events.
What I'mm doing is that I'm reading from the file descriptor of tts/1 using read(). What I have seen is that for a single key press I got the same key code twice(sometime thrice). I think that this is not a hardware issue. I' using standard UART code.
Anybody has any idea ?
You could do like most devices and just add a minimum delay between repeated keystrokes. I did that for a custom key input device on windows and it worked really well. It's the same as your keyboard. When you hold down a key, it pauses after the first reaction. Later repeats are faster but still have built in minimum delays.
(not sure if I'm phrasing it right but it worked great for me. I was writing a program to generate keystrokes as a reaction to repeating input signals.)

Resources