Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any equivalent of getch() from C++ in Java? [duplicate]

Is there any equivalent to C++’s getch() in Java? That is a function that moves the control forward as soon as a keyboard key is pressed, and also stores the character pressed.

I would like to use that function in a console app.

like image 653
Kamran Ahmed Avatar asked Jul 20 '13 05:07

Kamran Ahmed


People also ask

What is getch (); in C?

We use a getch() function in a C/ C++ program to hold the output screen for some time until the user passes a key from the keyboard to exit the console screen. Using getch() function, we can hide the input character provided by the users in the ATM PIN, password, etc.

Is Getch C or C++?

getch() is a nonstandard function and is present in conio. h header file which is mostly used by MS-DOS compilers like Turbo C. It is not part of the C standard library or ISO C, nor is it defined by POSIX. Like these functions, getch() also reads a single character from the keyboard.

What is the return value of getch ()?

This function does not take any parameters. Here, getch() returns the ASCII value of the character read from stdin . For example, if we give the character '0' as input, it will return the ASCII value of '0', which is 49. Now, in C / C++, we can directly convert a character to an integer.

Where is Getch declared?

Function getch in C program prompts a user to press a character. It doesn't show up on the screen. Its declaration is in "conio. h" header file.


1 Answers

There's no getch() function equivalent in java. But since you are not the first one who is asking about it, there are some solutions available:

  • Equivalent function to C's "_getch()" in Java?
  • http://www.overclockers.com/forums/showthread.php?t=471633

I think nothing has changed since then - I mean, no new getch() alike functions were added to Java.

like image 52
Qiu Avatar answered Sep 18 '22 13:09

Qiu