' ****************************************************************************************************************************************************************
' testmouse.c: A demonstration of how to use Rawinput to access multiple mice in Windows XP.
' https://jstookey.com/arcade/rawmouse/HelloRawInput.c
' ****************************************************************************************************************************************************************
' #define _WIN32_WINNT 0x0501 // Identify this as a Windows XP application.
' // This is necessary so we can access rawinput
' #include <stdio.h>
' #include <conio.h> // Provides getch()
' #include <windows.h> // Provides rawinput
' =============================================================================
' GLOBAL DECLARATIONS a$=string, i%=integer, L&=long, s!=single, d#=double
' -----------------------------------------------------------------------------
' BOOLEAN CONSTANTS
' -----------------------------------------------------------------------------
' USER DEFINED TYPES
' What is PRAWINPUTDEVICELIST?
' PRAWINPUTDEVICELIST:
' typedef struct tagRAWINPUTDEVICELIST {
' HANDLE hDevice;
' DWORD dwType;
' } RAWINPUTDEVICELIST, *PRAWINPUTDEVICELIST;
hDevice
AS _OFFSET ' a handle will always be _OFFSET dwType
AS LONG ' DWORD corresponds to LONG
' -----------------------------------------------------------------------------
' API FUNCTIONS
' What is GetRawInputDeviceList?
' UINT GetRawInputDeviceList(
' PRAWINPUTDEVICELIST pRawInputDeviceList,
' PUINT puiNumDevices, <---- what is a aPUINT?
' UINT cbSize
' );
' what is a aPUINT? According to
' WIN32 API Data Types
' https://www.csie.ntu.edu.tw/~r92094/c++/w32api_data_type.html
' PUINT Pointer to a UINT.
' Q: What QB64 type is equivalent to a pointer?
' A: is it _OFFSET ?
' COMPILER ERROR HERE: Expected &H... or &O...
' THEN WHEN I TRY CHANGING & TO &H OR &O, COMPILER SAYS MISSING )
' =============================================================================
' GLOBAL VARIABLES
' =============================================================================
' INITIALIZE
' =============================================================================
' START
main ProgramName$
' =============================================================================
' FINISH
SYSTEM ' return control to the operating system PRINT ProgramName$
+ " finished."
' /////////////////////////////////////////////////////////////////////////////
PRINT "MinimalRawInputTest% RETURNS: " + cstr$
( MinimalRawInputTest%
() )
'UINT nInputDevices;
' 1st call to GetRawInputDeviceList: Pass NULL to get the size of the list.
'if (GetRawInputDeviceList(NULL, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != 0) return 0;
' **********
' UNKNOWNS:
' Q1: how do you pass NULL in QB64?
' A1: ?
' Q2: what is &nInputDevices vs nInputDevices and what is the QB64 equivalent?
' A2: is it the pointer to the variable? in QB64, The _OFFSET function returns the memory offset of/within a given variable.
' Q3: what is the QB64 equivalent of sizeof?
' A3: maybe _MEM and _MEM.SIZE ?
MEM
= _MEM(RAWINPUTDEVICELIST
)
'IF (GetRawInputDeviceList(NULL, _OFFSET(nInputDevices), sizeof(RAWINPUTDEVICELIST)) <> 0) THEN
IF (GetRawInputDeviceList
(NULL
, _OFFSET(nInputDevices
), MEM.SIZE
) <> 0) THEN iResult% = 0
PRINT "Number of raw input devices: " + cstr$
(nInputDevices
) SLEEP ' SLEEP without an argument waits until a keypress.) iResult% = 1
' RETURN RESULT (ONE EXIT POINT!)
MinimalRawInputTest% = iResult%
' /////////////////////////////////////////////////////////////////////////////
' Equivalent to vbscript / VBA / VB6 cstr
'cstr$ = LTRIM$(RTRIM$(STR$(myValue)))
' /////////////////////////////////////////////////////////////////////////////
' Equivalent to getch
' -----------------------------------------------------------------------------
' What is getch?
' getch() is a nonstandard function and is present in conio.h header file
' which is mostly used by MS-DOS compilers like Turbo C. It is not part of
' the C standard library or ISO C, nor is it defined by POSIX.
' Like these functions, getch() also reads a single character from the
' keyboard. But it does not use any buffer, so the entered character is
' immediately returned without waiting for the enter key.
' Syntax: int getch(void);
' Parameters: This method does not accept any parameters.
' Return value: This method returns the ASCII value of the key pressed.
' -----------------------------------------------------------------------------
' QB64 alternate to getch
'
' SLEEP ' SLEEP without an argument waits until a keypress.)
'
' or
'
' DO
' x = _KEYHIT
' IF x THEN
' EXIT DO
' END IF
' LOOP