Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Terminal loses focus, what's the alternative?

    Hi all,

    I have a Java program running on a computer that accepts scans from a bunch of networked bar code scanners. The scanners send the bar code and then "Enter", which enters the data and starts a new line (using a while(true) loop and BufferedReader.readLine). I have not made any kind of an interface, just using the terminal. There's no direct interaction between a user and the computer so there isn't a need for an interface.

    My problem: The terminal will lose focus over time, so any "keyboard" input is lost. I have tried putting the command prompt into full screen however this does not work, it will eventually revert to the desktop. This is bad 'cause I lose scans and then the foreman comes and complains when his data isn't accurate :-[

    1) Is there any way (maybe non-Java related) to gaurantee the command window always has focus? Does it matter if I "C:\java programname" or programpackage.jar and run that?

    2) Would a full-screen interface maintain focus? Looked a little confusing to figure out but worth it if it solves my problem.

    Thanks in advance for any help!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Terminal loses focus, what's the alternative?

    Thread moved from Java 2D. What made you think this question might belong in that section?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Terminal loses focus, what's the alternative?

    How do the scanners "write" on the console? Is there a way to have that input go to the java program?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Terminal loses focus, what's the alternative?

    When you say you're using a terminal, do you mean a Java terminal like de.mud.terminal.Terminal from JavaSSH? If so, you might be able to gain focus whenever input is expected. See JComponent (Java Platform SE 6). But if you mean you're using a Java program running in a native terminal, it's probably a question for a forum dedicated to your particular OS or window manager.
    Get in the habit of using standard Java naming conventions!

  5. #5
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Re: Terminal loses focus, what's the alternative?

    I mean it's running in a native terminal (XP Pro). The scanners are HID devices and are just like a keyboard. The small part of my question, just in case someone who reads has a viable solution that isn't Java related, is how to keep focus.

    My actual Java question - would an interface of some kind be able to maintain focus all the time, or regain it if lost? Would going fullscreen prevent anything else from being able to steal focus? The machine is always running. It loses focus every few hours, and the only way I can restore it is using VNC. It would be ideal if it could run 24/7 and always be able to ensure it has focus.

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Terminal loses focus, what's the alternative?

    A Java GUI might be able to request focus. See How to Use the Focus Subsystem (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features). But it depends why it's losing it in the first place. This is a very OS-specific question, and you'll probably get a better answer on a OS-related forum.
    Get in the habit of using standard Java naming conventions!

  7. #7
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Re: Terminal loses focus, what's the alternative?

    Kind of an old thread now, but in case someone encounters the same issue and wants a quick fix:

    I first tried using a task scheduler that would close my app, and then run it again, and set cmd to run full screen. This worked all the time, except for some reason when it would kill/run at 5:00 am the java.exe window would APPEAR to have focus in the taskbar but didn't.

    So then I tried software that automatically clicks in the middle of the terminal window every minute, and it's fine. There's still that narrow amount of time where it may lose focus, and receive text before it gets clicked, but I think I'll accept 99% accuracy.

Similar Threads

  1. bufferedReader (or alternative)? Help!
    By seven in forum New To Java
    Replies: 1
    Last Post: 02-29-2012, 05:56 AM
  2. Replies: 7
    Last Post: 12-27-2011, 04:06 AM
  3. Alternative to JNLP
    By tecno40 in forum Java Applets
    Replies: 0
    Last Post: 12-22-2010, 01:38 AM
  4. Mac Terminal
    By Java8 in forum Other IDEs
    Replies: 0
    Last Post: 01-16-2010, 07:19 PM
  5. Terminal
    By dj kourampies in forum New To Java
    Replies: 7
    Last Post: 01-07-2009, 04:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •