Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 23 Sep 2015 12:49 PM |
i know the getasynckeystate but its so weird
and i cant tell if its pressed up or down
apparently if i hold the number will be -37111 or something, something about -3700
if its let up or pressed down it prints 1
very confusing
http://hastebin.com/axezahakur
(code)
i need a useful thing
on key presses
help? |
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 23 Sep 2015 01:44 PM |
GetAsyncKeyState() returns a short with the most significant bit (the one most left in binary) being set to 1 if the key is held down, or 0 if the key is not held down. Because of the way signed numbers are handled, this pretty much means that if what you get is negative then it's being held down, and if it's positive (including 0) then it's not.
Also, would that negative number happen to be -32768? Because that's the lowest range any variable of a short type can have. (1000 0000 0000 0000 in binary)
The reason that it returns 1 when the input direction is changed, is because the least significant bit will be set in that case to signify the change. The MSDN page says that this is unreliable, because other programs that use GetAsyncKeyState() could catch this before your program does and then not allow yours to catch it, so you shouldn't rely on it.
You can read more on it here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx
|
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 23 Sep 2015 01:47 PM |
yes it -32768
also,
does it detect when a button is pressed up?
becase when i hold it down and run tests at the same time in the console, then release it, it goes like this
-32768 -32768 -32768 -32768 1 (i release the button)
like
how can i tell the difference between a press and a release |
|
|
| Report Abuse |
|
|
| |
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 23 Sep 2015 01:54 PM |
It should be -32768 for a down state and 0 for an up state (assuming that none of the other bits are being set)
Also, if you're trying to get into game programming with C++, I'd recommend searching something called the "Allegro Game Programming Library". It can be used for creating 2D games and contains a lot of functions for things such as drawing images to the screen, loading and playing sounds, loading fonts, and keyboard input. It's also a lot better than trying to do everything by yourself at a low level.
There's also a nice tutorial on it: http://fixbyproximity.com/2d-game-development-course/ |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 23 Sep 2015 02:01 PM |
im just trying to learn c++ rn
also is there any way of detecting when a key is pressed without running loops because it would cause huge problems |
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 23 Sep 2015 02:05 PM |
| No, there's really no way to constantly do anything without loops. Even the events in Roblox that seem to just fire whenever something happens are checked and then fired on the lower level in a loop. |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
| |
|