[Petty] PB5.30b2 wrong import of GetAsyncKeyState_()
Posted: Sun Jun 01, 2014 4:32 pm
PS: I have marked the topic as "petty" on my own, not the PB-Team.
PB5.30b2 (x64/x86) on Windows 7 (x64)
The import of GetAsyncKeyState_() seems to be wrong. Due to MSDN the return value is defined as SHORT (link to MSDN). In PureBasic it seems to be defined as Integer which leads to some strange behaviour in some cases (see code and debugger output beyond).
Small additional info: Also due to MSDN the LSB is a legacy and not reliable. What counts is the (SHORT!) MSB. The official MSDN statement is that "ReturnValue & ~1" should be used to get the correct (non-legacy) result.
Beyond I've added "trigger comments" and marked the MSB in red. This is the x64 output. The x86 one looks essentially the same.
PB5.30b2 (x64/x86) on Windows 7 (x64)
The import of GetAsyncKeyState_() seems to be wrong. Due to MSDN the return value is defined as SHORT (link to MSDN). In PureBasic it seems to be defined as Integer which leads to some strange behaviour in some cases (see code and debugger output beyond).
Small additional info: Also due to MSDN the LSB is a legacy and not reliable. What counts is the (SHORT!) MSB. The official MSDN statement is that "ReturnValue & ~1" should be used to get the correct (non-legacy) result.
Code: Select all
Repeat
Delay( 500 )
Debug RSet( Bin( GetAsyncKeyState_( #VK_ESCAPE ) ) , 64 , "0" )
ForEver
Debugger wrote:1111111111111111111110101000000000000100111000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
1111111111111111111110101000000000000100111000000000000000000000 <- debugger stop button pressed
1111111111111111111110101000000000000100111000000000000000000000 <- debugger run button pressed
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
1111111111111111111110101000000000000100111000000000000000000000 <- debugger stop button pressed
1111111111111111111110101000000000000100111000000000000000000000 <- debugger run button pressed
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
1111111111111111111110101000000000000100111000000000000000000000 <- debugger stop button pressed
1111111111111111111110101000000000000100111000000000000000000000 <- debugger run button pressed
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
1111111111111111111110101000000000000100111111101000000000000001 <- key down
1111111111111111111110101000000000000100111111101000000000000001
1111111111111111111110101000000000000100111111101000000000000001
1111111111111111111110101000000000000100111111101000000000000001
1111111111111111111110101000000000000100111111101000000000000001 <- key up
1111111111111111111110101000000000000100111111100000000000000001
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
1111111111111111111110101000000000000100111111101000000000000001 <- key down
1111111111111111111110101000000000000100111111101000000000000001 <- key up
1111111111111111111110101000000000000100111111100000000000000001
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
1111111111111111111110101000000000000100111111101000000000000001 <- key down
1111111111111111111110101000000000000100111111101000000000000001
1111111111111111111110101000000000000100111111101000000000000001
1111111111111111111110101000000000000100111111101000000000000001
1111111111111111111110101000000000000100111111101000000000000001 <- key up
1111111111111111111110101000000000000100111111100000000000000001
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000