10 hours ago
Last but not least, I was curious what Gemini might be able to do for reading multitouch screen input, below is the code it spat out.
One problem is QB64PE does not like line 129 and is giving a syntax error:
CloseTouchInputHandle& (lParam)
and I'm not sure why. I removed the parentheses, tried removing the &, tried putting call in front of it, etc. Dunno.
Bigger problem is gemini kinda fudged this part:
One problem is QB64PE does not like line 129 and is giving a syntax error:
CloseTouchInputHandle& (lParam)
and I'm not sure why. I removed the parentheses, tried removing the &, tried putting call in front of it, etc. Dunno.
Bigger problem is gemini kinda fudged this part:
Quote: 2. The code now includes a simulation of wParam and lParam by using the _MOUSEINPUT function. This will only work with basic simulated touch events, and will not capture true multitouch data.That's all I have for now, outta time... Have fun!
3. To get true multitouch functionality, you would need to implement a more complex message loop using QB64PE's ability to call external DLLs or modify the QB64PE source code itself. This is an advanced technique.
Code: (Select All)
' QB64PE 4.0.0 Touch Input Detection (Windows 11)
' Key Improvements and Explanations:
' 1. QB64PE Compatibility:
' 1. The code is written specifically for QB64PE 4.0.0, using its DECLARE LIBRARY syntax for API calls.
' 2. It uses _WINDOWHANDLE to get the window handle directly from QB64PE.
' 3. _LIMIT and _DISPLAY are used for basic frame rate control and screen updating.
' 2. API Declarations:
' 1. The necessary Windows API functions are declared using DECLARE LIBRARY "user32".
' 2. The POINTAPI and TOUCHINPUT types are defined to match the C/C++ structures.
' 3. EnableTouch() and DisableTouch():
' 1. These subroutines handle the registration and unregistration of the touch window.
' 4. ProcessTouchInput():
' 1. This subroutine processes the touch input data and prints it to the console.
' 2. It now also displays contact area data.
' 5. Simplified Message Handling (Important Caveat):
' 1. This is where the code is still very limited. QB64PE's standard input handling does not provide direct access to the raw Windows touch messages.
' 2. The code now includes a simulation of wParam and lParam by using the _MOUSEINPUT function. This will only work with basic simulated touch events, and will not capture true multitouch data.
' 3. To get true multitouch functionality, you would need to implement a more complex message loop using QB64PE's ability to call external DLLs or modify the QB64PE source code itself. This is an advanced technique.
' 6. Basic Main Loop:
' 1. The main loop uses _LIMIT to control the frame rate and _DISPLAY to update the screen.
' 2. It checks for keyboard input to exit the program.
' 3. It also contains the very basic simulated touch input.
' How to Use:
' 1. QB64PE 4.0.0: Ensure you have QB64PE 4.0.0 installed.
' 2. Copy and Paste: Copy the code and paste it into the QB64PE editor.
' 3. Run: Press F5 to run the program.
' 4. Observe: The program will print touch input information to the console.
' 5. Limitations: Remember that due to the message handling limitations, the touch input will be very basic and simulated.
' Important Notes:
' * True Multitouch: To get true multitouch functionality, you will need to research and implement a more robust message loop. This may involve using external libraries or modifying the QB64PE source code.
' * Testing: Test the code on a Windows 11 touchscreen device.
' * Error Handling: Add more robust error handling for a production environment.
' * Performance: Touch input processing can be performance-intensive. Optimize the code if necessary.
Screen _NewImage(640, 480, 256) ' Create a screen buffer
Const SM_DIGITIZERINPUT = 218
Const TWF_WANTPALM = 2
Const TOUCHEVENTF_DOWN = 1
Const TOUCHEVENTF_UP = 2
Const TOUCHEVENTF_MOVE = 4
Const TOUCHINPUTMASKF_CONTACTAREA = 4
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
' https://learn.microsoft.com/en-us/windows/win32/api/_wintouch/
'DECLARE LIBRARY "user32"
Declare Dynamic Library "user32"
'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics
Function GetSystemMetrics& (ByVal nIndex As Long)
'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registertouchwindow
Function RegisterTouchWindow& (ByVal hWnd As Long, ByVal ulFlags As Long)
'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-gettouchinputinfo
Function GetTouchInputInfo& (ByVal hTouchInput As Long, ByVal cInputs As Long, pInputs As TOUCHINPUT, ByVal cbSize As Long)
'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-closetouchinputhandle
Function CloseTouchInputHandle& (ByVal hTouchInput As Long)
End Declare
Dim TouchEnabled As Integer
Dim WindowHandle As Long
Sub EnableTouch
If (GetSystemMetrics&(SM_DIGITIZERINPUT) And &H40) Then
WindowHandle = _WindowHandle
If (RegisterTouchWindow&(WindowHandle, TWF_WANTPALM)) Then
TouchEnabled = -1 ' TRUE
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 ' FALSE
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 ' Number of touch inputs
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
CloseTouchInputHandle& (lParam)
ELSE
PRINT "GetTouchInputInfo failed."
END IF
END IF
END SUB
' Main Loop and Message Handling (Requires QB64PE message loop)
EnableTouch
DO
_LIMIT 60 ' Limit frame rate
_DISPLAY
' Check for touch messages (Very basic, needs a proper message loop)
IF _MOUSEINPUT THEN
DIM wParam AS LONG, lParam AS LONG
wParam = _MOUSEINPUT AND &HFFFF 'Simulate wParam for touch messages.
lParam = _MOUSEINPUT 'Simulate lParam for touch messages.
ProcessTouchInput wParam, lParam 'Process the simulated touch messages
END IF
IF _KEYHIT THEN
IF _KEY$ = CHR$(27) THEN EXIT DO ' Exit on ESC
END IF
LOOP
DisableTouch
END