Wrong characters in KeyEvents generated from input of barcode scanner

Hi everybody, :-)
I have a problem with KeyEvents coming from a barcode scanner. The issue seems to have creeped in somewhere between JSE 6u3 and 6u10, as in the former it works as expected and in the latter it does not. The problem persists still, we also tested it with 6u22 and 6u23 (all tests were performed on the same Windows XP machine). The actual test client is very simple, the application is only a JFrame containing a JTextField and a JTextArea.
The barcode scanner we use connects via USB and has no special driver. The scanner already decodes the barcode that was scanned and "enters" characters in the focussed text field of the test application by emulating the Alt+NumPad behaviour (the character '5' being produced by the equivalent of holding Alt and entering "0053" on the NumPad).
Now, what appears when the application is run in JSE 6u03 is the expected result:
5@WM010$|
5@WM010$|
5@WM010$|
5@WM010$|
Here's the result for the same barcode when the application is run in JSE 6u10 (results for 6u23 are similar):
5@WÞ10ä
é@—M010$|
5@W¥ð104|
5°ùM0ó(▄♀
5@W¥010$|
é@WM010Ü\
é@W¥010P\
5@wy010$|
5@m01Ð$▄
)°W¥01è$|
)@—0ÑÐ$|
Well, at least it manages to get some characters right every time... ;-)
The character values are wrong already when the KeyEvent for each is being created and posted to the EventQueue. But on the other hand, the problem is obviously tied to the JSE used, so it has to occur somewhere after Java receives the input and before a KeyEvent is generated. Since the errors are very random, we are guessing that it might be a timing problem.
Between JSE 6u3 and 6u10, KeyEvent has received some new members (here with their typical values for my use case):
#isSystemGenerated     true
#primaryLevelUnicode     0     
#rawCode     0     
#scancode     0     
Maybe the problem could have been introduced in the same changeset? Or maybe the values observed are meaningful in a way?
Can anybody enlighten me, or give me a hint of any kind? I already scoured the bug database but did not find anything.
Thanks! Any help is appreciated!
Regards, Lars

@mriem: Yes, I did. In all cases, it is "windows-1252". And moreover, if it were a problem with the default character set, it would not show the random behaviour it does.
I also managed to create a reproducer that shows the behaviour:
import static java.awt.event.KeyEvent.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class ScannerTest {
     private static final String TEST = "5@WM010$|";
     private static final int DELAY = 50;
     private static final Map<Character, int[]> ALT_CODES = new HashMap<Character, int[]>();
     static {
          ALT_CODES.put('5', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD5, VK_NUMPAD3 });
          ALT_CODES.put('@', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD6, VK_NUMPAD4 });
          ALT_CODES.put('W', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD7, VK_NUMPAD7 });
          ALT_CODES.put('M', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD8, VK_NUMPAD7 });
          ALT_CODES.put('0', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD4, VK_NUMPAD8 });
          ALT_CODES.put('1', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD4, VK_NUMPAD9 });
          ALT_CODES.put('$', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD3, VK_NUMPAD6 });
          ALT_CODES.put('|', new int[] { VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD4 });
     public static void main(String[] args) throws Exception {
          System.out.println(java.nio.charset.Charset.defaultCharset().name());
          final int delay = DELAY;
          final JFrame frame = new JFrame("ScannerTest");
          SwingUtilities.invokeAndWait(new Runnable() {
               @Override
               public void run() {
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    JScrollPane scrollPane = new JScrollPane(new JTextArea());
                    scrollPane.setPreferredSize(new Dimension(300, 600));
                    frame.add(scrollPane);
                    frame.pack();
                    frame.setVisible(true);
          new Thread() {
               @Override
               public void run() {
                    try {
                         Robot robot = new Robot();
                         for (int c = 0; c < 1000; c++) {
                              if (frame.isActive()) {
                                   for (int i = 0; i < TEST.length(); i++) {
                                        int[] codes = ALT_CODES.get(TEST.charAt(i));
                                        if (frame.isActive()
                                                  && !(codes == null || codes.length == 0)) {
                                             robot.keyPress(VK_ALT);
                                             for (int code : codes) {
                                                  robot.keyPress(code);
                                                  robot.keyRelease(code);
                                             robot.keyRelease(VK_ALT);
                                        robot.delay(delay);
                                   robot.keyPress(VK_ENTER);
                                   robot.keyRelease(VK_ENTER);
                              } else {
                                   c--;
                                   try {
                                        Thread.sleep(delay);
                                   } catch (InterruptedException e) {
                                        e.printStackTrace();
                    } catch (AWTException e) {
                         e.printStackTrace();
          }.start();
}

Similar Messages

  • Solution for wrong characters in KeyEvents generated with ALT method

    Hi everybody!
    There is still a problem with KeyEvents coming from a barcode scanner using ALT + NumPad method. Java generates KeyTyped events with random outputs when ALT key is pressed. The issue seems to have creeped in somewhere between JSE 6u3 and 6u10, as in the former it works as expected and in the latter it does not. The problem persists still, we also tested it with Java 8 (on Windows 8, Windows 7 and Ubuntu 14). The actual test client is very simple, the application is only a JFrame containing a JTextField and a JTextArea.
    The old thread: Wrong characters in KeyEvents generated from input of barcode scanner
    My solution is to register a KeyEventDispatcher that blocks the KeyEvents when the ALT method is active:
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(
      new AltBugFixKeyEventDispatcher());
    public class AltBugFixKeyEventDispatcher implements KeyEventDispatcher {
        private int i = -1;
        @Override
        public boolean dispatchKeyEvent(KeyEvent ke) {
            if (ke.isAltDown()) {
                switch (ke.getID()) {
                    case KeyEvent.KEY_PRESSED:
                        if(ke.getKeyCode() == KeyEvent.VK_ALT){
                            i = 0;
                        }else if(Character.isDigit(ke.getKeyChar())){
                            i++;
                        }else{
                            i = -1;
                        break;
                    case KeyEvent.KEY_RELEASED:
                        break;
                    case KeyEvent.KEY_TYPED:
                        break;
                if(i != -1){
                    return true;
            return false;

    Hi everybody!
    There is still a problem with KeyEvents coming from a barcode scanner using ALT + NumPad method. Java generates KeyTyped events with random outputs when ALT key is pressed. The issue seems to have creeped in somewhere between JSE 6u3 and 6u10, as in the former it works as expected and in the latter it does not. The problem persists still, we also tested it with Java 8 (on Windows 8, Windows 7 and Ubuntu 14). The actual test client is very simple, the application is only a JFrame containing a JTextField and a JTextArea.
    The old thread: Wrong characters in KeyEvents generated from input of barcode scanner
    My solution is to register a KeyEventDispatcher that blocks the KeyEvents when the ALT method is active:
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(
      new AltBugFixKeyEventDispatcher());
    public class AltBugFixKeyEventDispatcher implements KeyEventDispatcher {
        private int i = -1;
        @Override
        public boolean dispatchKeyEvent(KeyEvent ke) {
            if (ke.isAltDown()) {
                switch (ke.getID()) {
                    case KeyEvent.KEY_PRESSED:
                        if(ke.getKeyCode() == KeyEvent.VK_ALT){
                            i = 0;
                        }else if(Character.isDigit(ke.getKeyChar())){
                            i++;
                        }else{
                            i = -1;
                        break;
                    case KeyEvent.KEY_RELEASED:
                        break;
                    case KeyEvent.KEY_TYPED:
                        break;
                if(i != -1){
                    return true;
            return false;

  • Java reading data from a wireless barcode scanner

    Hello,
    In my project, the application has to read data (barcode) from a wireless Rf scanner. The application will be developed using java which has to process the data read by rf scanner.Could anyone please tell me how can I go about this?
    Any help would be greatly appreciated.
    Thanks
    Durga

    Hi Durga,
    I'm afraid you question has nothing to do with Java. Try to find some info about the scanner you are going to use. Firstly, there are 2 kind of scanners:
    - programmable (with their own logic)
    - non-programmable
    If you are going to use a non-programmable scanner (these scanners are able just to read a bar-code and send it back as a string of characters), you have probably no problem at all. Some scanners send the characters via keyboard standard input (the same as if you type the code's content via keyboard), some send it via serial link, UBS, etc. - here, you would have to implement a listener on the port.
    The programmable scanners have usually their own protocols, so here your solution may vary according to the possibilities supported by the producer/vendor. (Some of standards are that scanners are like a DOS/Windows machines running on TCP-IP, AS400 clients, etc.)
    If the latter is your option, my suggestion is the following: do not buy the scanners if the vendor is not able to support you as for the software part of the solution (otherwise, you are going to have really hard times)

  • Issue with Czech characters in PDFs generated from RSTXPDFT4

    Hi,
    We have a requirement to generate PDF documents from the spool of the Billing document outputs in our project.
    For this we are using the standard program RSTXPDFT4, which converts the SAP script OTF to PDF format.
    But the Czech characters in the billing document output are not getting displayed in the PDF generated out of it.
    We are already using a device type I2HP4 when creating the print request , which supports Latin-2 Character set ( ISO 8859-2 ), to which the special characters
    of East European languages belong.
    Even then , the czech characters are not getting displayed in the PDF generated.
    We have raised  a message to SAP for this, and SAP informed us that currently the only solution to this is to use Latin 2 soft fonts,
    and to upload these soft fonts into R/3 System using report RSTXPDF2 as they contain the Eastern European special characters plus all the other characters in ISO 8859-2.
    But, since character font definitions (font files) are protected by copyrights, SAP informed us that they cannot provide these font files and we have to acquire
    these latin-2 font files by searching in search engines in the internet.
    If anyone has the information where we can get these "Adobe type 1 Latin-2" font files with '.PFB' extension,  for the proper display of Czech characters, please let me know.

    Hi,
    Did you or anyone manage to find a reasonable solution for this issue?
    I'm currently facing something similar but with Polish characters instead.
    I tried using RSTXPDF2 to upload .PFB and .TTF files but to no avail.

  • ADF application input fields barcode

    Hi ,
    I would like to understand that, if  an application developed in ADF, does ADF input fields support the values read by barcode scanner. For example on a form if there are 2 fields which are needed to be input by barcode scanner, can we have these 2 fields to support reading of the data from barcode scanner?
    In oracle form based application, this is very much achievable.
    Appreciate your response on this.
    Thanks,
    Sai

    Hi,
    there is no functionality in ADF for this. However, if your barcode scanner has a plugin for the browser to write to an HTML field then I don't see why it should not work. Have you checked the capabilities and configuration options of your barcode scanner? What does it say?
    Frank

  • I cannot import a Quicktime file (.mov) which I generated from a slide show out of iPhoto8 in iMovie8 (filename is grey); what did I wrong?

    I cannot import a Quicktime file (.mov) which I generated from a slide show out of iPhoto8 in iMovie8 (filename is grey); what did I wrong?

    iMovie 08 will only import files that contain codecs that it can edit. It will generally import audio and video codecs that iPhoto generates. However, if your iPhoto slideshow contains a manual advance track, iMovie cannot edit this and therefore will not import. In iPhoto, check to see if you can do a timed advance rather than a manual advance. Then it should import.

  • Does LabView program behave differentl​y under Traditiona​l Chinese version from regular English version. The program reads in numbers and characters from input files.

    Does LabView program behave differently under Traditional Chinese version from regular English version. The program reads in numbers and characters from input files.

    Hope this helps,
    Ankita

  • Unable to pick unicode characters from input file using "outside in"

    Hi,
    I am using your product "Outside in" to read unicode text from input
    source file. For reading text I am using TReadFirst and TReadNext even
    though "It is not picking unicode characters from input source file
    and also it is giving zunk character to the buffer". How can I
    retrieve unicode character from input source using "outside in"
    product. Your help makes me learn more stuff.
    Regards,
    Naresh.D

    I am trying to use CAReadFirst and CAReadNext to read unicode characters. Even it is not picking, I think is there any flags we need to set. can any one help to this.

  • Reader 9.0.0 - Clipboard exports wrong characters

    Hi,
    I've been trying to copy text from a pdf file into Windows Notepad.
    Apparently, Acrobat Reader 9 sends wrong characters to the clipboard. Here's some text from AR9 (Android_Apps.pdf):
    "Biometric authen5ca5on system
    currently suppor5ng iris based
    authen5ca5on"
    It seems AR9 changes "ti" into "5". How come?
    Axel Dahmen

    >But yet, doesn't pdf store the original text in addition to ligatures?
    No. There's no capability to do that, and even if there was, no way to
    force the PDF creator to use it.
    What a PDF creator generally sees is a reference to a single character
    in a font. In good cases, the character in the font uses a standard
    like like "fi", "fl" or "ffi". This stuff gets stored into the PDF.
    And there is a mapping into the Unicode ligatures. Acrobat is
    actually fairly smart on text extraction: if you are extracting text
    with a known ligature, and the operating system doesn't support it
    (like using "fi" on Windows) it does generate a pair of characters.
    However, "ti" is not a standard ligature, and doesn't exist in Unicode
    so far as I've seen. This is fancy typography, but a problem.
    Aandi Inston

  • [SOLVED]TTY's wrong characters in manpage

    Sorry about last post because I really need a picture to illustrate my problem and it seems not easy to add a picture from local computer in this forum.So,this time,I'll detailly describe the problem in words.
    For example,when I input 'man rxvt' in X,the screen will show some contents,and one line of them will be like followed:
    rxvt, version 2.7.10, is a colour vt102 terminal emulator intended as an xterm(1) replace‐
    However,when I put in the same command in TTY,the last character of the same line will be another wrong character,uh,particularly said is 'E' with a slash above it,so the output is like this:
    rxvt, version 2.7.10, is a colour vt102 terminal emulator intended as an xterm(1) replaceE
    Absolutely,it's just an example above.Actually,I can see many wrong characters('E' with a slash over it) in the manpage(so far I can only find the problem in manpage).
    And I have read a few wiki or some websites but I couldn't find why.Maybe it's hard for me.
    Last edited by fool (2014-02-22 23:40:43)

    Well, it was worth a shot
    edit:  Read the wiki: "locale.conf contains a new-line separated list of environment variable assignments: besides LANG, it supports all the LC_* variables, with the exception of LC_ALL.
    Last edited by frank604 (2014-02-22 19:31:10)

  • How to show custom header in pdf generated from report

    Hi,
    I  have created a report that is used to display Leave record of employees in an organization. After which it creates a pdf file and send it to respective HOD.
    In this case I am trimming generated output and sendinf only required fields to the pdf.
    When pdf is getting generated it shows program name as Title of that report.
    I want to change this header to my own header along with some variable but not sure how I can do so.
    I have also tried TOP-OF_PAGE but problem in this case is that I am still getting program name along with it.
    To generate pdf I have used function :
      call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
        exporting
          src_spoolid   = spoolid
          no_dialog     = ' '
        importing
          pdf_bytecount = l_no_of_bytes
          pdf_spoolid   = l_pdf_spoolid
          btc_jobname   = l_jobname
          btc_jobcount  = l_jobcount
        tables
          pdf           = l_pdfdata.
    Then I had converted this pdf to Binary
    call function 'QCE1_CONVERT'
        tables
          t_source_tab         = l_pdfdata
          t_target_tab         = lit_record
        exceptions
          convert_not_possible = 1
          others               = 2.
    Then I had created subject matter and used FM : SO_NEW_DOCUMENT_ATT_SEND_API1: to send mail to respective HODs.
    I tried dubbing it but couldn't get any variable which is holding program name.
    Sorry for putting in wrong forum.
    so Closing it from this forum and raising the same in ABAp-General forum.
    How to change header of pdf in generated report
    Edited by: gaur.yagyesh on Apr 16, 2010 4:03 PM

    To make it more clear to my question.
    I am using sun one webserver 6.0 sp6.
    I need to enable custom header on the webserver so that any request having a custom http header coming to webserver should be captured by the webserver.
    Thanks,

  • How to include CDATA in xml generated from XQuery

    I need to include Cdata in the xml generated from my xquery which is given below:
    I tried using XMLCDATA, but not getting the desired output. What am I doing wrong?
    SELECT XMLQuery('<InsUpdDel>
    for $crv in ora:view("RELATION")
    return
    <first>
    <eff_date>{$crv/ROW/EFF_DATE/text()}</eff_date>
    <source>{$crv/ROW/SOURCE/text()}</source>
    <key>
    <fld>
    <id>from_type</id>
    <val>XMLCDATA({$crv/ROW/FROM_ENT_TYPE/text()})</val>
    </fld>
    <fld>
    <id>from_ent_id</id>
    <val>{$crv/ROW/FROM_ENT_ID/text()}</val>
    </fld>
    </key>
    </first>}</InsUpdDel>'
    RETURNING CONTENT)
    FROM dual;
    The output I get is XMLCDATA(C), while the desired output is <![CDATA[C]]>

    Forgive me my vanity to think I can contribute by kicking doors open that are probably already wide open....I might create more confusion, but perhaps it helps some of the readers of this thread....
    In general it is not such a good idea to use "string" functions to create (serialized) XML. XML tools (including Oracle XML DB) go through a lot of effort to make sure that when a "native" XML structure is serialized to a string, the XML rules are strictly obeyed (e.g. special character escaping).
    Just assume e.g. that the $i/Reference from above contains something like ]]><
    The resulting XML would not be valid.
    More info on serializing XML in the context of XQuery is available from
    - http://www.w3.org/TR/xquery/#id-serialization
    - http://www.w3.org/TR/xslt-xquery-serialization/
    - http://www.w3.org/TR/xslt-xquery-serialization/#XML_CDATA-SECTION-ELEMENTS
    Unfortunately I do not think Oracle XML DB currently implements these parts of the spec (perhaps 11g will)...leaving the OP's question unanswered.
    Anyway, if going the route of serializing the XML through string functions, it is always good to realize the dangers of such an approach.
    Peter

  • Trouble playing a PDF generated from Captivate

    I have Adobe Pro and Flash Player 11.1, but unable to play a PDF generated from a Captivate file. The first message I get when I publish is "Note:To view the generated PDF file, you must have Adobe Reader version 9 or later."
    When I open the generated PDF, i get this message "TO view the Flash technology content in this PDF file, please install the required version of Flash Player."
    WHat am I missing or doing wrong?

    You may want to ask in the Captivate forum, as this would likely be something that can be remedied with different "Save" settings. My experience with Captivate is limited, so I can't really offer anything I'd be 100% sure of.

  • FM FOR CREATING NEW CONDITION RECORDS FROM INPUT FILE

    Hello vikas,
    I need to develop a interface program FOR CREATING NEW CONDITION RECORDS FROM INPUT FILE.
    Is there ay function module to update or create the condtion records,
    if u have any example interface program to update conditions records please send me.
    regards
    ram.

    This must be your compiler output.
    Basically, it is telling you two things that are wrong - in syntax.
    1. On line number 11 of the file RationalCollection1.java, the compiler expects a type identifier - that would be the object or return type such as int, String, boolean, etc.
    The reason it is doing this is probably due to your not ending a previous statement - like the "expected ';'" error statement. Check your code, make sure that methods (brackets) are closed correctly and there are no open statements (i.e. missing the semi-colen at the end).
    2. On line number 33 of the file RationalCollection1.java, the compiler expected the closing bracket. Thus, you didn't put the bracket where the compiler wants it.
    It appears that you have skipped some lines of code. Those lines are the problem, post them - post lines 30-36 and 9-15 so we can see what is happening around those error lines.

  • CTRL-M (^M) characters in data read from sockets

    Hi,
    We have developed a software applications which opens upto 300 TCP connections and 4000 UDP sockets. The data from the TCP application is multiplexed to UDP sockets and viceversa.
    We connect to the application using a TCP socket and send certain data to the application which in turns sends this data to all the 4000 UDP sockets. The data received from 4000 UDP sockets is in turn sent back to the TCP socket as responses.
    We used telnet to connecct to thespecific TCP port on our application, sent a request to be sent to all 4000 UDP sockets and noticed ctrl-M characters in the data received from TCP socket. However we are sure we are not appending or adding this ctrl-m character while sending the data on TCP socket.
    telnet host port >/tmp/abc
    send a request
    send next request
    (after 10 mins, close connection)
    cat -vet /tmp/abc >/tmp/xyz
    There are ctrl-m characters in /tmp/xyz.
    ^M is observed only at the end of few lines and not on all lines. Successive repeatition of this test generates ^M in different lines but at the end of the line always.
    Can anybody help me to know why these ^M characters are getting generated?
    Note: We are completely working on Solaris and do not move contents across Windows and Unix. Our application is completely written on C++
    Thanks.
    Message was edited by:
    shekhnam

    I think I've misunderstood something here. The problem you're having is with the response being filtered by Telnet or your client, not what telnet is sending to the server?
    In that case I think the explanation is clear. Telnet is trying to display what comes back on a screen, and it is deleting and inserting newlines every now and then according to its internal whim so as to make the data wrap. I don't know if you can control that, but I also don't know if it matters as long as you have your own client application. You just have to stop treating Telnet as a viable test client.

Maybe you are looking for