Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Shift State - solution
Message
From
06/02/2019 23:30:11
 
 
To
06/02/2019 16:12:38
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01665978
Message ID:
01666000
Views:
56
>>I solved the shift state issue I had. The ShiftState() fuction returns a integer with the bits set to the bit set to whether the Shift, Ctrl, Alt key are currently depressed. I know, I know, I should not have had to explain the obvious, but...
>
>One potential issue when using GetKeyState() instead of GetAsyncKeyState() is that GetKeyState() will only report what has currently been consumed by your app's internal message queue. If the Title Bar reads "Not responding" your message queue isn't being processed, and if there are keys in the typeahead buffer that have not yet been processed, your function will be retrieving old/stale data from the time the keys were typed in and not their current state.
>
>If you use GetAsyncKeyState(), it can have other undesirable effects, in that the state is the current / immediate one regardless of how far ahead of the typeahead buffer your app is. It also specifies if the key has been pressed since the last time GetAsyncKeyState() was pressed, so it sort of holds a buffer if the key has been pressed if it was pressed and released in-between two calls.
>
>This is actually a fast way for you to inject code in your application to remove the "Not Responding" state, by polling GetAsyncKeyState() to see if some keys have been pressed (shift keys, control, alt, mouse buttons), you can then (when they have been pressed) issue DOEVENTS or DOEVENTS FORCE to process the message queue, and make that Not Responding go away, but to do so in a way that isn't always doing it, but only when the user is pressing keys and clicking buttons.
>

Good advise. Especially when a routine has the potential of getting into a infinite loop. The GetAsyncKeyState() would provide a possible means to exiting the loop.

Thanks.

>>
>>
>>CLEAR
>>DO WHILE INKEY(1)#27
>>    ? bitshow(ShiftState(),3)
>>ENDDO
>>
>>PROCEDURE ShiftState
>>    DECLARE INTEGER GetKeyState IN user32 INTEGER nVirtKey
>>    LOCAL nBit AS INTEGER
>>    nBit = 0
>>    nBit = IIF(BITTEST(GetKeyState( 0x10 ),8),BITSET(nBit,0),nBit)    && Shift
>>    nBit = IIF(BITTEST(GetKeyState( 0x11 ),8),BITSET(nBit,1),nBit)    && Ctrl
>>    nBit = IIF(BITTEST(GetKeyState( 0x12 ),8),BITSET(nBit,2),nBit)    && Alt
>>    RETURN nBit
>>ENDPROC
>>
>>PROCEDURE bitshow
>>    LPARAMETERS tn AS LONG , nlen AS INTEGER
>>    LOCAL s, i
>>    mlen = IIF(EMPTY(nlen),32,nlen)
>>    s = []
>>    FOR i=0TO 31
>>        s = IIF(BITTEST(tn,i),[1],[0]) + s
>>    NEXT
>>    RETURN RIGHT(s,nlen)
>>ENDPROC
>>
>>
>>
>>Another tool for your toolbox.
Greg Reichert
Previous
Reply
Map
View

Click here to load this message in the networking platform