' ****************************************************************************************************************************************************************
' 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 ?
' Petr: Just information for you, if you use User32.dll
' and then rewrite GetRawInputDeviceList& as GetRawInputDeviceList,
' then it start (maybe badly?) working, it returns zero Raw devices for me.
'DECLARE DYNAMIC LIBRARY "kernel32"
' 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%
) INPUT "PRESS <ENTER> TO CONTINUE", in$
'UINT nInputDevices;
DIM MyList
AS RAWINPUTDEVICELIST
' 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
' http://www.qb64.org/wiki/MEM
' The _MEM variable type can be used when working with memory blocks. It has no variable type suffix.
' The _MEM type contains the following read-only elements where name is the _MEM variable name:
' name.OFFSET is the current start position in the memory block AS _OFFSET. Add bytes to change position.
' name.SIZE is the remaining size of the block at current position in bytes AS _OFFSET
' name.TYPE is the type (represented as bits combined to form a value) AS _OFFSET:
MEM
= _MEM(RAWINPUTDEVICELIST
) size&& = ConvertOffset(MEM.SIZE)
'IF (GetRawInputDeviceList(NULL, _OFFSET(nInputDevices), sizeof(RAWINPUTDEVICELIST)) <> 0) THEN
IF (GetRawInputDeviceList
(MyList
, MyAddr
, 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%
' /////////////////////////////////////////////////////////////////////////////
' Hi. I try using Steve McNeill's function for offset converting,
' so program is now compiled and run, but wrote,
' that this function not exists in kernel32.dll:
m
= _MEM(value
) 'Point it to use value 'On 64 bit OSes, an OFFSET is 8 bytes in size. We can put it directly into an Integer64
_MEMGET m
, m.OFFSET
, ConvertOffset&&
'Get the contents of the memblock and put the values there directly into ConvertOffset&& 'However, on 32 bit OSes, an OFFSET is only 4 bytes. We need to put it into a LONG variable first
_MEMGET m
, m.OFFSET
, temp&
'Like this ConvertOffset&& = temp& 'And then assign that long value to ConvertOffset&&
' /////////////////////////////////////////////////////////////////////////////
' Equivalent to vbscript / VBA / VB6 cstr
'cstr$ = LTRIM$(RTRIM$(STR$(myValue)))
' /////////////////////////////////////////////////////////////////////////////
' Converting C to QB64 notes:
' PUINT?
' https://www.daniweb.com/programming/software-development/threads/1767/c-data-types
' Platform SDK: Win32 API Data Types
' https://www.csie.ntu.edu.tw/~r92094/c++/w32api_data_type.html
' Pointers? sizeof?
' https://qb64.org/wiki/OFFSET_(function)
' https://www.qb64.org/wiki/Using_OFFSET
' http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index_topic_10328-0/
' ^^^
' cached version: http://webcache.googleusercontent.com/search?q=cache:y5SVJL1obEQJ:www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index_topic_10328-0/+&cd=1&hl=en&ct=clnk&gl=us
' sizeof?
' https://www.qb64.org/forum/index.php?topic=2427.0
' https://www.qb64.org/wiki/MEMELEMENT
' NULL values?
' Google passing null value to api function in qb64
' https://www.google.com/search?q=passing+null+value+to+api+function+in+qb64
' _UNSIGNED equivalent of UINT
' QB64 _UNSIGNED
' http://www.qb64.org/wiki/UNSIGNED#:~:text=Explanation%3A%20In%20QB64%20an%20unsigned,by%20the%20value%20minus%2065536.&text=Explanation%3A%20The%20maximum%20value%20can,the%20FOR%20loop%20repeats%20itself.
' declaring API libraries
' https://www.qb64.org/wiki/DECLARE_LIBRARY
' https://www.qb64.org/forum/index.php?topic=2930.60
' Other QB64
' QB64 Keyword Reference - By usage
' https://www.qb64.org/wiki/Keyword_Reference_-_By_usage
' GetRawInputDeviceList function (winuser.h) 12/05/2018
' https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdevicelist
' RAWINPUTDEVICELIST structure (winuser.h) 12/05/2018
' https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputdevicelist
' About Raw Input 05/31/2018
' https://docs.microsoft.com/en-us/windows/win32/inputdev/about-raw-input
' winuser.h -- USER procedure declarations, constant definitions and macros
' https://ecs.syr.edu/faculty/fawcett/Handouts/coreTechnologies/windowsprogramming/WinUser.h
' RawInput example: luluco250/MouseRaw.cpp
' https://gist.github.com/luluco250/ac79d72a734295f167851ffdb36d77ee
' -----------------------------------------------------------------------------
' 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
' -----------------------------------------------------------------------------
' windows api definitions, RawInput, Windows C headers, etc.
' -----------------------------------------------------------------------------
' Winuser.h header - Win32 apps | Microsoft Docs
' https://docs.microsoft.com/en-us/windows/win32/api/winuser/
' GetRawInputDeviceList function (winuser.h) 12/05/2018
' https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdevicelist
' GetRawInputDeviceInfoA function (winuser.h) 12/05/2018
' https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdeviceinfoa
' GetRawInputDeviceList and GetRawInputDeviceInfo APIs in PowerBuilder.
' https://community.appeon.com/index.php/qna/q-a/getrawinputdevicelist-and-getrawinputdeviceinfo-apis-in-powerbuilder