Fixed the errors and cleaned it up a little, and it runs, sort of.
Gemini's comments seemed to say that this is only simulating touchscreen ability,
but they're declaring functions like RegisterTouchWindow and GetTouchInputInfo,
so it looks like it should be able to do it for real.
Only when I run it, it says "Touch input disabled." which is hogwash,
because I'm running it on my touchscreen laptop which I know works,
because I just closed the QB64PE window by touching the screen, LOL.
If anyone wants to see if you can get this working, be my guest!
I'm done for today!
Gemini's comments seemed to say that this is only simulating touchscreen ability,
but they're declaring functions like RegisterTouchWindow and GetTouchInputInfo,
so it looks like it should be able to do it for real.
Only when I run it, it says "Touch input disabled." which is hogwash,
because I'm running it on my touchscreen laptop which I know works,
because I just closed the QB64PE window by touching the screen, LOL.
If anyone wants to see if you can get this working, be my guest!
I'm done for today!
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.
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 ' TOUCHINPUT
' 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 Shared TouchEnabled As Integer
Dim Shared WindowHandle As Long
Dim wParam As Long
Dim lParam As Long
Screen _NewImage(640, 480, 256) ' Create a screen buffer
' Main Loop and Message Handling (Requires QB64PE message loop)
EnableTouch
Do
' Check for touch messages (Very basic, needs a proper message loop)
If _MouseInput Then
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
_Display
_Limit 60 ' Limit frame rate
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 ' 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 ' EnableTouch
Sub DisableTouch
TouchEnabled = 0 ' FALSE
Print "Touch input disabled."
End Sub ' DisableTouch
Sub ProcessTouchInput (wParam As Long, lParam As Long)
Dim value1&
Dim cInputs As Long
Dim tInputs(0 To cInputs - 1) As TOUCHINPUT
Dim input1 As TOUCHINPUT
If (TouchEnabled) Then
cInputs = wParam And &HFFFF ' Number of touch inputs
If (GetTouchInputInfo&(lParam, cInputs, tInputs(0), Len(tInputs(0)))) Then
For i = 0 To cInputs - 1
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
value1& = CloseTouchInputHandle&(lParam)
Else
Print "GetTouchInputInfo failed."
End If
End If
End Sub ' ProcessTouchInput