Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading multitouch touchscreen input
#3
I thought I was done, but then I got a "bright idea" to ask gemini to generate the real multitouch code, and it came up with some code where it guessed / assumed / hallucinated that QB64PE has an _EVENT keyword. I told it there was an error, and it kept going down that path... 

QB64PE 4.0.0 is reporting Syntex error at the line:
_EVENT eventInfo ' Corrected line

Code snippet

Code: (Select All)
' QB64PE 4.0.0 True Multitouch Input Detection (Windows 11)
 
' Key Improvements:
' 1. Direct Message Loop: Implements a direct message loop using _EVENTINFO and _EVENT functions, allowing for the capture of WM_TOUCH messages.
' 2. Multitouch Support: Processes multiple touch inputs simultaneously.
' 3. Accurate Touch Data: Retrieves accurate touch data, including contact area and touch flags.
' 4. Improved Error Handling: Includes basic error handling for API calls.
 
Const SM_DIGITIZERINPUT = 218
Const TWF_WANTPALM = 2
Const TOUCHEVENTF_DOWN = 1
Const TOUCHEVENTF_UP = 2
Const TOUCHEVENTF_MOVE = 4
Const TOUCHINPUTMASKF_CONTACTAREA = 4
Const WM_TOUCH = &H240
 
Type POINTAPI
    x As Long
    y As Long
End Type
 
Type TOUCHINPUT
    x As Long
    y As Long
    hSource As Long
    dwID As Long
    dwFlags As Long
    dwMask As Long
    dwTime As Long
    dwExtraInfo As Long
    cxContact As Long
    cyContact As Long
End Type
 
Type _EVENTINFO ' Added the missing type definition
    eventType As Long
    wParam As Long
    lParam As Long
    time As Long
End Type
 
Declare Dynamic Library "user32"
    Function GetSystemMetrics& (ByVal nIndex As Long)
    Function RegisterTouchWindow& (ByVal hWnd As Long, ByVal ulFlags As Long)
    Function GetTouchInputInfo& (ByVal hTouchInput As Long, ByVal cInputs As Long, pInputs As TOUCHINPUT, ByVal cbSize As Long)
    Function CloseTouchInputHandle& (ByVal hTouchInput As Long)
End Declare
 
Dim Shared TouchEnabled As Integer
Dim Shared WindowHandle As Long
 
Screen _NewImage(640, 480, 256)
 
EnableTouch
 
Do
    Dim eventInfo As _EVENTINFO
    Do
        Call _EVENT(eventInfo) ' Corrected line
        If eventInfo.eventType = 0 Then Exit Do ' No more events
        If eventInfo.eventType = WM_TOUCH Then
            ProcessTouchInput eventInfo.wParam, eventInfo.lParam
        End If
    Loop
 
    _Display
    _Limit 60
Loop Until _KeyDown(27)
 
_AutoDisplay
DisableTouch
 
End
 
Sub EnableTouch
    If (GetSystemMetrics&(SM_DIGITIZERINPUT) And &H40) Then
        WindowHandle = _WindowHandle
        If (RegisterTouchWindow&(WindowHandle, TWF_WANTPALM)) Then
            TouchEnabled = -1
            Print "Touch input enabled."
        Else
            Print "Failed to enable touch input."
        End If
    Else
        Print "Touch input is not supported on this device."
    End If
End Sub
 
Sub DisableTouch
    TouchEnabled = 0
    Print "Touch input disabled."
End Sub
 
Sub ProcessTouchInput (wParam As Long, lParam As Long)
    If (TouchEnabled) Then
        Dim cInputs As Long
        cInputs = wParam And &HFFFF
        Dim tInputs(0 To cInputs - 1) As TOUCHINPUT
        If (GetTouchInputInfo&(lParam, cInputs, tInputs(0), Len(tInputs(0)))) Then
            For i = 0 To cInputs - 1
                Dim input1 As TOUCHINPUT
                input1 = tInputs(i)
                Print "Touch ID: "; input1.dwID
                Print "X: "; input1.x / 100
                Print "Y: "; input1.y / 100
                Print "Flags: "; input1.dwFlags
                If (input1.dwFlags And TOUCHEVENTF_DOWN) Then
                    Print "Touch Down"
                ElseIf (input1.dwFlags And TOUCHEVENTF_UP) Then
                    Print "Touch Up"
                ElseIf (input1.dwFlags And TOUCHEVENTF_MOVE) Then
                    Print "Touch Move"
                End If
                If (input1.dwMask And TOUCHINPUTMASKF_CONTACTAREA) Then
                    Print "Contact Area X: "; input1.cxContact / 100
                    Print "Contact Area Y: "; input1.cyContact / 100
                End If
            Next i
            Dim value1&
            value1& = CloseTouchInputHandle&(lParam)
        Else
            Print "GetTouchInputInfo failed."
        End If
    End If
End Sub

Reasoning for the fix:
The error "Syntax error at the line _EVENT eventInfo" arises because QB64PE requires the Call keyword when calling a subroutine with arguments. In QB64, while sometimes the Call keyword is optional, it is required in this instance.
By changing the line to:
Code snippet
Call _EVENT(eventInfo)
We explicitly use the Call keyword, which tells QB64PE that we are calling a subroutine and passing the eventInfo variable as an argument. This resolves the syntax error and allows the code to compile and run correctly.
 
Gemini can make mistakes, so double-check it
Reply


Messages In This Thread
RE: reading multitouch touchscreen input - by madscijr - Today, 04:30 AM



Users browsing this thread: 2 Guest(s)