Date: 02-16-2022
Return to Index
created by gbSnippets
'The GetKeyState provides information about the state of the keys at the time
'an event took place. This is different from the API function GetAsyncKeyState,
'which gives the status of the keys at the time the API is called. Both return 0
'if the key is not down.
'Primary Code:
iResult1& = GetAsyncKeyState(%vk_shift)
iResult2& = GetAsyncKeyState(%vk_control)
iResult1& = GetAsyncKeyState(%vk_menu) 'alt-key
iResult1& = GetAsyncKeyState(%vk_lbutton)
iResult2& = GetAsyncKeyState(%vk_rbutton)
'Compilable Example: (Jose Includes)
'This examples uses a timer to periodically check the state of
'a key (alt-key in this case).
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Label, hDlg, 100,"", 50,10,100,20
SetTimer(hDlg, 200, 50, 0) 'creates the timer 200ms
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Timer
Local iResult&
iResult& = GetAsyncKeyState(%vk_menu) '0 if not pressed
Control Set Text hDlg, 100, Str$(iResult&)
End Select
End Function
'gbs_00194
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm