Is there any equivalent of getch() from C++ in Java?
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.
Is there an equivalent of getch() function in Mac?
You probably want to look at ncurses. It has a lot in common with conio. You can get its documentation with "man ncurses".
Read any key to continue Java
The only way which I found was whith JNI and C.
Is there an equivalent for getch() in Scala?
scala.Console.readChar
, aliased in in current incarnations of Scala as Predef.getChar
is the most direct way.
scala> readChar
res0: Char = !
UPDATE
This time without the pesky Enter
:
scala> Console.in.read.toChar
res0: Char = !
getch is deprecated
Microsoft decided to mark the name without underscore deprecated, because those names are reserved for the programmer to choose. Implementation specific extensions should use names starting with an underscore in the global namespace if they want to adhere to the C or C++ Standard - or they should mark themselves as a combined Standard compliant environment, such as POSIX/ANSI/ISO C, where such a function then corresponds to one of those Standards.
Read this answer about getcwd() too, for an explanation by P. J. Plauger, who knows stuff very well, of course.
If you are only interested to wait for some keys typed by the user, there really is no reason not to use getchar
. But sometimes it's just more practical and convenient to the user to use _getch
and friends. However, those are not specified by the C or C++ Standard and will thus limit the portability of your program. Keep that in mind.
Related Topics
Auto Adjust the Height of Rows in a Jtable
Why Does Collections.Sort Use Mergesort But Arrays.Sort Does Not
Jtable + Sorting Specific Field
How to Shutdown an Executorservice
A Rotated Square Panel in Java Gui
Why Does This Subtraction Not Equal Zero
How to Change Background Color of Jtabbedpane
How to Write Swap Method in Java
How to Log Spring 5 Webclient Call
How Is Driver Class Located in Jdbc4
Hibernate: "Field 'Id' Doesn't Have a Default Value"
How to Escape Reserved Words in Hibernate's Hql
What Are the Rules Dictating the Inheritance of Static Variables in Java
How to Dynamically Build a Multi-Dimensional Array in Java