r/badcode • u/GLIBG10B š§ Gentoo salesmanš§ • Feb 26 '22
c++ My attempt at checking for pressed keys using the Windows API
336
Upvotes
r/badcode • u/GLIBG10B š§ Gentoo salesmanš§ • Feb 26 '22
43
u/GLIBG10B š§ Gentoo salesmanš§ Feb 26 '22 edited Feb 26 '22
The code:
69
u/Looooong_Man Feb 26 '22
I'm not familiar with C++, so pardon me. But... "Titerator"? LOL
129
u/Knuffya Feb 26 '22
The windows API is a fucking mess, which only exists because of backwards compatibility.
16
u/djhayman Feb 27 '22
Or you could call the single function GetKeyboardState (https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getkeyboardstate) to get the state of every key on the keyboard in one go.
15
u/Rakkachi Feb 26 '22
Really simple, damn...
13
u/__Raptor__ Feb 26 '22
iirc
initializer_listshould be passed by value and used immediately. If you need to re-use it, just use a vector5
u/Kalaschnik0pf Feb 27 '22
"Titerator"
3
u/stahkh Feb 27 '22
Is it even possible to use Windows API without it looking like a whole lot of jumbled mess? I am honestly interested and eager to see a best practice example.
1
u/mynamejeffyesi Apr 13 '22
Are you looking for all keys currently pressed or just any specific keys? Because if its the latter just use GetAsyncKeyState? Pretty sure theres a way to get everything however I've never bothered researching that far, also heard that this is bad practice from someone, so take this with a grain of salt.