getch returns 2 characters when I type one

岁酱吖の 提交于 2019-11-29 15:08:09

Well, crap!

It's a (rather new) bug in windows.

https://developercommunity.visualstudio.com/content/problem/247770/-getch-broken-in-vs-157.html

"When building a console application using the _getch() function suddenly returns two times for each keypress"

got the following response from microsoft:

" Thanks for reporting this! This will be fixed on a future windows update."

UPDATE: As stated in the link above, setting the runtime to statically link with a previous version of the C runtime will fix the issue, but you need to make sure all your related projects (if you are building a library, for example) also use the same runtime. (I tested it)

If you don't want to (or you can't) use a previous version of the Universal C Runtime, you can use _getwch instead of _getch, as the problem doesn't affect to _getwch function.

Note that _getwch can return Unicode characters, so it may return distinct values than _getch for some keys. For example, for character, _getch returns 0x3f (?) while _getwch returns 0x20ac (Unicode value for €)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!