• <bdo id='oG1SF'></bdo><ul id='oG1SF'></ul>

    <small id='oG1SF'></small><noframes id='oG1SF'>

    <tfoot id='oG1SF'></tfoot>

      <i id='oG1SF'><tr id='oG1SF'><dt id='oG1SF'><q id='oG1SF'><span id='oG1SF'><b id='oG1SF'><form id='oG1SF'><ins id='oG1SF'></ins><ul id='oG1SF'></ul><sub id='oG1SF'></sub></form><legend id='oG1SF'></legend><bdo id='oG1SF'><pre id='oG1SF'><center id='oG1SF'></center></pre></bdo></b><th id='oG1SF'></th></span></q></dt></tr></i><div id='oG1SF'><tfoot id='oG1SF'></tfoot><dl id='oG1SF'><fieldset id='oG1SF'></fieldset></dl></div>

      <legend id='oG1SF'><style id='oG1SF'><dir id='oG1SF'><q id='oG1SF'></q></dir></style></legend>
    1. 控制台应用程序中的 Java 键盘输入解析

      时间:2023-09-26

              <bdo id='laa3S'></bdo><ul id='laa3S'></ul>
              <tfoot id='laa3S'></tfoot>

                <tbody id='laa3S'></tbody>
                <legend id='laa3S'><style id='laa3S'><dir id='laa3S'><q id='laa3S'></q></dir></style></legend>
              • <i id='laa3S'><tr id='laa3S'><dt id='laa3S'><q id='laa3S'><span id='laa3S'><b id='laa3S'><form id='laa3S'><ins id='laa3S'></ins><ul id='laa3S'></ul><sub id='laa3S'></sub></form><legend id='laa3S'></legend><bdo id='laa3S'><pre id='laa3S'><center id='laa3S'></center></pre></bdo></b><th id='laa3S'></th></span></q></dt></tr></i><div id='laa3S'><tfoot id='laa3S'></tfoot><dl id='laa3S'><fieldset id='laa3S'></fieldset></dl></div>

                <small id='laa3S'></small><noframes id='laa3S'>

                本文介绍了控制台应用程序中的 Java 键盘输入解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我刚刚开始使用 JLine 在控制台模式下解析字符输入.它似乎运作良好,但我想知道:

                I've just started messing around with JLine to parse character input in console mode. It seems to work well, but I'm wondering:

                在 JLine 中是否有一种非阻塞方式来确定字符是否可用?(即像 kbhit() 在 Windows 中.)

                Is there a nonblocking way in JLine to find out if characters are available? (i.e. like kbhit() in Windows.)

                我想我总是可以将键盘输入包装在它自己的线程中,然后在线程安全队列中将键盘字符提供给主线程,但这似乎是不必要的.

                I suppose I could always wrap keyboard input in its own thread which then offers the keyboard characters in a thread-safe queue to the main thread, but that seems like it should be unnecessary.

                EDIT:这是逐个字符的解析.我不会使用 GUI.Java 中控制台模式下通常的 InputStream I/O 要求您先按 Enter 键(例如,它只是缓冲输入).请不要告诉我在控制台模式下逐个字符输入在 Java 中是不可能的;不是.JLine 使用具有平台相关实现的可移植接口来实现.

                EDIT: This is character-by-character parsing. I am not going to use a GUI. The usual InputStream I/O in Java in console mode requires you to hit the Enter key first (e.g. it's buffered input only). Please don't tell me character-by-character input in console mode is impossible in Java; it isn't. JLine does it using a portable interface with a platform-dependent implementation.

                编辑更新:我能够组合一个帮助类来在工作线程中执行阻塞 I/O(使用 JLine 进行每个字符的 I/O,警告:你必须自己解析 Ctrl-C!) &然后通过一个带有 isempty() 例程的同步队列进行通信.对于我现在正在做的事情,这很好,但我真的很想知道在未来做这件事的好方法.

                Edit update: I was able to hack together a helper class to do the blocking I/O in a worker thread (using JLine for the per-character I/O, warning: you have to parse Ctrl-C yourself!) & then communicate via a synchronized queue with an isempty() routine. For what I'm doing right now that's fine, but I would really like to know a Good Way To Do This In The Future.

                推荐答案

                你似乎走对了.

                我认为执行此操作的正确"方法是使用工作线程将所有阻塞 I/O 倒入非阻塞队列中.看看 ConcurrentLinkedQueue 来自 java.util.并发.

                I think the "right" way to do this is a worker thread that pours all the blocking I/O into a non-blocking queue. Hava a look at ConcurrentLinkedQueue from java.util.concurrent.

                这篇关于控制台应用程序中的 Java 键盘输入解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何判断按下了哪个 SHIFT 键? 下一篇:系统覆盖android 4.0

                相关文章

                最新文章

                  <bdo id='Ctd2y'></bdo><ul id='Ctd2y'></ul>
                1. <small id='Ctd2y'></small><noframes id='Ctd2y'>

                  <legend id='Ctd2y'><style id='Ctd2y'><dir id='Ctd2y'><q id='Ctd2y'></q></dir></style></legend>

                  1. <tfoot id='Ctd2y'></tfoot>
                    <i id='Ctd2y'><tr id='Ctd2y'><dt id='Ctd2y'><q id='Ctd2y'><span id='Ctd2y'><b id='Ctd2y'><form id='Ctd2y'><ins id='Ctd2y'></ins><ul id='Ctd2y'></ul><sub id='Ctd2y'></sub></form><legend id='Ctd2y'></legend><bdo id='Ctd2y'><pre id='Ctd2y'><center id='Ctd2y'></center></pre></bdo></b><th id='Ctd2y'></th></span></q></dt></tr></i><div id='Ctd2y'><tfoot id='Ctd2y'></tfoot><dl id='Ctd2y'><fieldset id='Ctd2y'></fieldset></dl></div>