# waitKey without delay

**URL:** <https://forum.opencv.org/t/waitkey-without-delay/3582>\
**Category:** Uncategorized\
**Tags:** highgui\
**Created:** [May 29, 2021, 3:01am UTC](https://forum.opencv.org/t/waitkey-without-delay/3582 "2021-05-29T03:01:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chucklamar](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@Chucklamar](https://forum.opencv.org/u/Chucklamar)\
**Post date:** [May 29, 2021, 3:01am UTC](https://forum.opencv.org/t/waitkey-without-delay/3582/1 "2021-05-29T03:01:48Z")

</div>

My experience is that waitkey(1) waits AT LEAST a millisecond, when I use it to display an image in my code I see a delay of about 5 ms. Currently looking for a way around using waitkey to display an image and avoid that delay.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [May 29, 2021, 8:25am UTC](https://forum.opencv.org/t/waitkey-without-delay/3582/2 "2021-05-29T08:25:06Z")

</div>

that’s why I’ve introduced [`pollKey`](https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga6d20fbd3100ec3badc1eaa653aff99d7). currently only works properly on win32 because I don’t care about (or can build/test) other GUI libraries.

“at least” comes from the granularity of the OS scheduler and how it treats sleep calls.

“at most” means it’ll wait **less** , if a key was hit.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [May 29, 2021, 8:40am UTC](https://forum.opencv.org/t/waitkey-without-delay/3582/3 "2021-05-29T08:40:47Z")

</div>

> [@Chucklamar](#):
>
> looking for a way around using waitkey to display an image and avoid that delay.

you probably can’t. waitKey() will trigger the blitting, no update without it

(@crackwitz , `pollKey()` just drains the msg queue, but does not trigger any drawing messages, right ? (and that only on win32, else it will call `waitKey(1)`))

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [May 29, 2021, 8:43am UTC](https://forum.opencv.org/t/waitkey-without-delay/3582/4 "2021-05-29T08:43:56Z")

</div>

> [@berak](#):
>
> (@crackwitz , `pollKey()` just drains the msg queue, but does not trigger any drawing messages, right ? (and that only on win32, else it will call `waitKey(1)` ))

wrong. it absolutely handles messages, which causes drawing. it works until the queue is empty and then exits, instead of waiting/sleeping for new messages to arrive.

and yes, that’s win32. everywhere else (Qt, gtk, …) it’s a waitkey(1) because nobody came along and implemented this for other GUI toolkits that I can’t build or test.

yes, those things are misnomers. the choices were (1) stick with the naming scheme (2) keep it consistent but rename (then waitKey disappears/is deprecated) (3) be inconsistent.
