changeset 20786:a8ee668e7fd7 stable

Fix kbhit and pause on Windows systems. * configure.ac: Add check for function _getch. * sysdep.cc (octave_kbhit): Use _getch, _kbhit on Windows platforms to correctly implement kbhit functionality.
author Rik <rik@octave.org>
date Wed, 02 Dec 2015 14:05:37 -0800
parents 51ab9145f6e6
children 62564952e161 a2b96b523472
files configure.ac libinterp/corefcn/sysdep.cc
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Fri Nov 27 16:49:44 2015 -0500
+++ b/configure.ac	Wed Dec 02 14:05:37 2015 -0800
@@ -2282,7 +2282,7 @@
 AC_CHECK_FUNCS([select setgrent setpwent siglongjmp strsignal])
 AC_CHECK_FUNCS([tcgetattr tcsetattr tgammaf toascii])
 AC_CHECK_FUNCS([umask waitpid])
-AC_CHECK_FUNCS([_kbhit])
+AC_CHECK_FUNCS([_getch _kbhit])
 
 dnl There are no workarounds in the code for missing these functions.
 AC_CHECK_FUNCS([modf pow sqrt sqrtf], [],
--- a/libinterp/corefcn/sysdep.cc	Fri Nov 27 16:49:44 2015 -0500
+++ b/libinterp/corefcn/sysdep.cc	Wed Dec 02 14:05:37 2015 -0800
@@ -513,8 +513,15 @@
 int
 octave_kbhit (bool wait)
 {
-#ifdef HAVE__KBHIT
-  int c = (! wait && ! _kbhit ()) ? 0 : std::cin.get ();
+#ifdef HAVE__KBHIT && HAVE__GETCH
+  // This essentially means we are on a Windows system.
+  int c;
+
+  if (wait)
+    c = _getch ();
+  else
+    c = (! _kbhit ()) ? 0 : _getch ();
+
 #else
   raw_mode (true, wait);