From 4e7b5214387e74b8df1c847d64b68e4bb3876d91 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 15 Dec 2016 14:17:38 +0300 Subject: [PATCH] highgui: change waitKey() default behaviour The old behaviour is available via waitKeyEx() call or via setting of OPENCV_LEGACY_WAITKEY environment variable --- modules/highgui/include/opencv2/highgui.hpp | 9 +++++++++ modules/highgui/src/window.cpp | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/highgui/include/opencv2/highgui.hpp b/modules/highgui/include/opencv2/highgui.hpp index 2f005da..16ef8c4 100644 --- a/modules/highgui/include/opencv2/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui.hpp @@ -320,6 +320,15 @@ CV_EXPORTS_W void destroyAllWindows(); CV_EXPORTS_W int startWindowThread(); +/** @brief Similar to #waitKey, but returns full key code. + +@note + +Key code is implementation specific and depends on used backend: QT/GTK/Win32/etc + +*/ +CV_EXPORTS_W int waitKeyEx(int delay = 0); + /** @brief Waits for a pressed key. The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\leq 0\f$ ) or for delay diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index f9496f5..9306f8e 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -201,11 +201,26 @@ double cv::getWindowProperty(const String& winname, int prop_id) return cvGetWindowProperty(winname.c_str(), prop_id); } -int cv::waitKey(int delay) +int cv::waitKeyEx(int delay) { return cvWaitKey(delay); } +int cv::waitKey(int delay) +{ + int code = waitKeyEx(delay); +#ifndef HAVE_WINRT + static int use_legacy = -1; + if (use_legacy < 0) + { + use_legacy = getenv("OPENCV_LEGACY_WAITKEY") != NULL ? 1 : 0; + } + if (use_legacy > 0) + return code; +#endif + return code & 0xff; +} + int cv::createTrackbar(const String& trackbarName, const String& winName, int* value, int count, TrackbarCallback callback, void* userdata) -- 2.7.4