하나의 문자만 입력 받을 때(getch와 비슷하게) in Java

조성현의 이미지

getch와 비슷한 함수가 자바에 존재하는지 모르겠습니다.

api 문서를 계속 뒤져도 :shock: 나오지가 않는 군요.

보통 EOF나 Enter를 눌러야만 인식을 하게 되더라구요.

물론 socket 메소드에서의 setSoTimeout 메소드를 사용해서 타이머를 측정해도 되겠지만, NonBlocking도 해야겠고(이것도 못찾겠음), 아무튼 여러가지 손이 들어가게 되더군요.

딱 한 문자만 입력 받고 싶습니다.

vim 편집기에서와 같이 h,j,k,l 키를 누르면 움직이는 상태와 같이 말입니다.

어떤 상태를 말씀 드린지는 아실 거라 생각이 듭니다.

아시는 분은 알려주시기 바랍니다. 편법이라도(강제로 EOF를 준다던가. 하는...) 괜찮습니다.

vacancy의 이미지

기억이 가물가물한데,
swing이었나 awt였나의 상황에서는,
enableEvents였나로 키보드 이벤트를 감지하고
processKeyEvent였나로 이벤트 처리를 했었는데요.

text환경이시라면 잘 모르겠네요.

asteroid의 이미지

제가 아는 범위에서, Java 에서의 stdin에서

리얼타임으로 입력을 받아오는 방법은 없습니다;;;

그리고, non-blocking I/O에 대한 부분은 j2se 1.4에 새로 추가된

java.nio 패키지를 참고해보세요.

leanblue의 이미지

다음 글은 Sun사에서 예전에 올라왔던 글입니다.

http://java.sun.com/features/2002/09/pword_mask.html

예전에 본적이 있어서 comman line password 로 검색을 하니

그 글이 바로 나오는군요..^^

윗글은 커맨드 라인에서 패스워드를 입력받는 프로그램에 대한 글인데

패스워드 입력시 입력 받은 문자를 읽고

재빨리 프롬프트 문자열을 출력시켜주는 방식을 쓰고 있습니다.

자바월드와 Sun사의 글 모두에서 '될수 있으면 JNI를 이용해서 구현하라'라고 하고 있고

Sun사에서 제공한 방법은 임시적 방편입니다.

위의 글에서는

Quote:
Note: Since this solution makes extensive use of threads, if the machine is under heavy load, there is no guarantee that MaskingThread will run often enough.

와 같이 밝히고 있습니다.

참고해보시기 바랍니다.

LeanBlue in CyberWorld!!!

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.