How do you make a button act like the computer keyboard- repeating the action after a short wait?
Conrad
Conrad
#COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" FUNCTION PBMAIN () AS LONG LOCAL hDlg AS LONG DIALOG NEW %NULL, "Repeat Button", 10,10, 140,100 TO hDlg CONTROL ADD BUTTON, hDlg, 101, "Press <SPCBAR> and hold", 10,10,120, 14 DIALOG SHOW MODAL Hdlg CALL CBPROC END FUNCTION CALLBACK FUNCTION cbProc() AS LONG LOCAL hCtrl AS LONG, dwProc AS DWORD SELECT CASE CBMSG CASE %WM_INITDIALOG CONTROL HANDLE CBHNDL, 101 TO hCtrl dwProc = SetWindowLong (hctrl, %GWL_WNDPROC, CODEPTR(BtnProc)) SetWindowLong hctrl, %GWL_USERDATA, dwProc CASE %WM_COMMAND IF CBCTL = 101 THEN MessageBeep %MB_OK END IF CASE %WM_DESTROY CONTROL HANDLE CBHNDL, 101 TO hCtrl SetWindowLong hCtrl, %GWL_WNDPROC, GetWindowLong (hCtrl, %GWL_USERDATA) END SELECT END FUNCTION FUNCTION BtnPRoc (BYVAL hWnd AS LONG, BYVAL wMSG AS LONG, BYVAL wParam AS LONG, BYVAL lPAram AS LONG) AS LONG SELECT CASE AS LONG wMSg CASE %WM_KEYDOWN SendMessage hWnd, %BM_CLICK, %NULL, %NULL END SELECT FUNCTION = CallWIndowProc (GetWindowLong(hWnd, %GWL_USERDATA), hWNd, wMSg, wParam, lparam) END FUNCTION
#Compile Exe #Dim All #Include "WIN32API.INC" %BTN_Test = 102 %LBL_LABEL1 = 101 Function GetKBDelay(KBDelay As Dword) As Dword ' TT Tonny Bjorn ' If the SystemParametersInfo() function succeeds, the return value is nonzero. Function = SystemParametersInfo(%SPI_GETKEYBOARDDELAY, 0, KBDelay, 0) End Function '------------------/GetKBDelay Function GetKBSpeed(KBSpeed As Dword) As Dword ' If the SystemParametersInfo() function succeeds, the return value is nonzero. Function = SystemParametersInfo(%SPI_GETKEYBOARDSPEED, 0, KBSpeed, 0) End Function '------------------/GetKBSpeed Function SubClassProc(ByVal hWnd As Dword, ByVal wMsg As Dword, _ ByVal wParam As Dword, ByVal lParam As Long) As Long Local lRes, oldProc, KBDelay, KBSpeed As Dword Dialog Get User GetParent(hWnd), 1 To oldProc GetKBDelay(KBDelay) : KBDelay = (KBDelay + 1) * 250 ' SPI_GETKEYBOARDDELAY (0 - 3 = 250 - 1000ms) GetKBSpeed(KBSpeed) : KBSpeed = 400 - (KBSpeed * 12) ' SPI_GETKEYBOARDSPEED (0 - 31 = 400 - 30ms) Select Case As Long wMsg Case %WM_LBUTTONDOWN SetTimer hWnd, 1, KBDelay, 0 ' Set timer for repeat delay Case %WM_LBUTTONUP KillTimer hWnd, 1 : KillTimer hWnd, 2 WinBeep 800, 20 Case %WM_TIMER Select Case wParam Case 1 SetTimer hWnd, 2, KBSpeed, 0 ' Set timer for repeat speed Case 2 KillTimer hWnd, 1 WinBeep 800, 20 End Select End Select Function = CallWindowProc(oldProc, hWnd, wMsg, wParam, lParam) End Function '------------------/SubClassProc CallBack Function DlgProc() Local hBtn, oldProc As Dword Select Case As Long CbMsg Case %WM_INITDIALOG ' Subclass the button Control Handle CbHndl, %BTN_Test To hBtn oldProc = SetWindowLong(hBtn, %GWL_WNDPROC, CodePtr(SubClassProc)) Dialog Set User CbHndl, 1, oldProc Case %WM_COMMAND Select Case As Long CbCtl Case %BTN_Test If CbCtlMsg = %BN_CLICKED Then 'MsgBox "Test" End If End Select End Select End Function '------------------/DlgProc Function PBMain() Local hDlg As Dword Dialog New 0, "Click-o-matic Button test", , , 200, 120, %WS_CAPTION Or %WS_SYSMENU, To hDlg Control Add Label, hDlg, %LBL_LABEL1, "Click'n'hold", 75, 25, 120, 20 Control Add Button, hDlg, %BTN_Test, "Test", 75, 60, 50, 15 Dialog Show Modal hDlg, Call DlgProc End Function '------------------/PbMain
<Jog> <Run> <Stop>
<Jog> Click Once <Run> Click and Hold <Stop> Release
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment