Python OpenCV – waitKeyEx() Function
Python OpenCv waitKeyEx() method is similar to waitKey() method but it also returns the full key code. The key code which is returned is implementation-specific and depends on the used backend: QT/GTK/Win32/etc.
- delay: The time in milliseconds after which windows needs to destroyed. If given 0 it waits for infinite till any key is pressed to destroy window.
Return : This method return the full key code of the key which is pressed. If no key is pressed it return -1.
In the below example we have implemented the waitKeyEx() method we have made a window that has an image named “gfg_logo.png” and then we display it and using waitKeyEx() method we delay the closing of the window and then press a key to close it. We store the returned value in the full_key_code variable and print it.
The key code is:13
In the output, the value of full_key_code will be printed according to the key pressed When we press enter the value that is printed is as follows.
Another Example we can see is where we don’t press any key and wait for the window to destroy automatically after the delay that is given. We will pass 5000 as a parameter to wait for 5 seconds and then a window will close automatically without the need of pressing any key. In this case the function will return -1 as no key was pressed.
The key code is:-1