#include "FiveWin.ch"
#define WM_INPUT 0x00FF
function Main()
local oWnd := TMyWindow():New()
oWnd:SetText( "Raw Input test" )
MsgInfo( RegisterRawInputDevices( oWnd:hWnd ) )
oWnd:Activate()
return nil
CLASS TMyWindow FROM TWindow
CLASSDATA lRegistered
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyWindow
if nMsg == WM_INPUT
MsgBeep() // ok, we are receiving WM_INPUT messages
endif
return Super:HandleEvent( nMsg, nWParam, nLParam )
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#define RIDEV_INPUTSINK 0x00000100
typedef struct tagRAWINPUTDEVICE
{
USHORT usUsagePage;
USHORT usUsage;
DWORD dwFlags;
HWND hwndTarget;
} RAWINPUTDEVICE, * PRAWINPUTDEVICE, * LPRAWINPUTDEVICE;
typedef BOOL WINAPI ( * PREGISTERRAWINPUTDEVICES ) (
PRAWINPUTDEVICE pRawInputDevices,
UINT uiNumDevices,
UINT cbSize
);
HB_FUNC( REGISTERRAWINPUTDEVICES )
{
RAWINPUTDEVICE rid;
PREGISTERRAWINPUTDEVICES pRegisterRawInputDevices;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pRegisterRawInputDevices = ( PREGISTERRAWINPUTDEVICES ) GetProcAddress( hUser32, "RegisterRawInputDevices" );
rid.usUsagePage = 0x01;
rid.usUsage = 0x06;
rid.dwFlags = RIDEV_INPUTSINK;
rid.hwndTarget = ( HWND ) hb_parnl( 1 );
hb_retl( pRegisterRawInputDevices( &rid, 1, sizeof( RAWINPUTDEVICE ) ) );
FreeLibrary( hUser32 );
}
#pragma ENDDUMP
#include "FiveWin.ch"
#define WM_INPUT 0x00FF
function Main()
local oWnd := TMyWindow():New()
oWnd:SetText( "Raw Input test" )
MsgInfo( RegisterRawInputDevices( oWnd:hWnd ) )
oWnd:Activate()
return nil
CLASS TMyWindow FROM TWindow
CLASSDATA lRegistered
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyWindow
if nMsg == WM_INPUT
MsgBeep() // ok, we are receiving WM_INPUT messages
endif
return Super:HandleEvent( nMsg, nWParam, nLParam )
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#define RIDEV_INPUTSINK 0x00000100
typedef struct tagRAWINPUTDEVICE
{
USHORT usUsagePage;
USHORT usUsage;
DWORD dwFlags;
HWND hwndTarget;
} RAWINPUTDEVICE, * PRAWINPUTDEVICE, * LPRAWINPUTDEVICE;
typedef BOOL WINAPI ( * PREGISTERRAWINPUTDEVICES ) (
PRAWINPUTDEVICE pRawInputDevices,
UINT uiNumDevices,
UINT cbSize
);
HB_FUNC( REGISTERRAWINPUTDEVICES )
{
RAWINPUTDEVICE rid[ 2 ];
PREGISTERRAWINPUTDEVICES pRegisterRawInputDevices;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pRegisterRawInputDevices = ( PREGISTERRAWINPUTDEVICES ) GetProcAddress( hUser32, "RegisterRawInputDevices" );
rid[ 0 ].usUsagePage = 0x01;
rid[ 0 ].usUsage = 0x02; // Mouse
rid[ 0 ].dwFlags = RIDEV_INPUTSINK;
rid[ 0 ].hwndTarget = ( HWND ) hb_parnl( 1 );
rid[ 1 ].usUsagePage = 0x01;
rid[ 1 ].usUsage = 0x06; // Keyboard
rid[ 1 ].dwFlags = RIDEV_INPUTSINK;
rid[ 1 ].hwndTarget = ( HWND ) hb_parnl( 1 );
hb_retl( pRegisterRawInputDevices( rid, 2, sizeof( RAWINPUTDEVICE ) ) );
FreeLibrary( hUser32 );
}
#pragma ENDDUMP
// Windows Raw Input API support demo, (c) FiveTech Software
#include "FiveWin.ch"
#define WM_INPUT 0x00FF
function Main()
local oWnd := TMyWindow():New()
oWnd:SetText( "Raw Input test" )
MsgInfo( RegisterRawInputDevices( oWnd:hWnd ) )
oWnd:Activate()
return nil
CLASS TMyWindow FROM TWindow
CLASSDATA lRegistered
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyWindow
if nMsg == WM_INPUT
MsgBeep() // ok, we are receiving WM_INPUT messages
endif
return Super:HandleEvent( nMsg, nWParam, nLParam )
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#define RIDEV_INPUTSINK 0x00000100
#define RID_INPUT 0x10000003
typedef struct tagRAWINPUTDEVICE
{
USHORT usUsagePage;
USHORT usUsage;
DWORD dwFlags;
HWND hwndTarget;
} RAWINPUTDEVICE, * PRAWINPUTDEVICE, * LPRAWINPUTDEVICE;
typedef BOOL WINAPI ( * PREGISTERRAWINPUTDEVICES ) (
PRAWINPUTDEVICE pRawInputDevices,
UINT uiNumDevices,
UINT cbSize
);
typedef struct tagRAWINPUTHEADER {
DWORD dwType;
DWORD dwSize;
HANDLE hDevice;
WPARAM wParam;
} RAWINPUTHEADER, * PRAWINPUTHEADER;
typedef struct tagRAWMOUSE {
USHORT usFlags;
union {
ULONG ulButtons;
struct {
USHORT usButtonFlags;
USHORT usButtonData;
};
};
ULONG ulRawButtons;
LONG lLastX;
LONG lLastY;
ULONG ulExtraInformation;
} RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;
typedef struct tagRAWKEYBOARD {
USHORT MakeCode;
USHORT Flags;
USHORT Reserved;
USHORT VKey;
UINT Message;
ULONG ExtraInformation;
} RAWKEYBOARD, *PRAWKEYBOARD, *LPRAWKEYBOARD;
typedef struct tagRAWHID {
DWORD dwSizeHid;
DWORD dwCount;
BYTE bRawData;
} RAWHID, **LPRAWHID;
typedef struct tagRAWINPUT {
RAWINPUTHEADER header;
union {
RAWMOUSE mouse;
RAWKEYBOARD keyboard;
RAWHID hid;
} data;
} RAWINPUT, * PRAWINPUT, * LPRAWINPUT;
typedef UINT WINAPI ( * PGETRAWINPUTDATA ) (
LPRAWINPUT hRawInput,
UINT uiCommand,
LPVOID pData,
PUINT pcbSize,
UINT cbSizeHeader
);
HB_FUNC( REGISTERRAWINPUTDEVICES )
{
RAWINPUTDEVICE rid[ 2 ];
PREGISTERRAWINPUTDEVICES pRegisterRawInputDevices;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pRegisterRawInputDevices = ( PREGISTERRAWINPUTDEVICES ) GetProcAddress( hUser32, "RegisterRawInputDevices" );
rid[ 0 ].usUsagePage = 0x01;
rid[ 0 ].usUsage = 0x02; // Mouse
rid[ 0 ].dwFlags = RIDEV_INPUTSINK;
rid[ 0 ].hwndTarget = ( HWND ) hb_parnl( 1 );
rid[ 1 ].usUsagePage = 0x01;
rid[ 1 ].usUsage = 0x06; // Keyboard
rid[ 1 ].dwFlags = RIDEV_INPUTSINK;
rid[ 1 ].hwndTarget = ( HWND ) hb_parnl( 1 );
hb_retl( pRegisterRawInputDevices( rid, 2, sizeof( RAWINPUTDEVICE ) ) );
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWINPUTDATA )
{
UINT dwSize;
LPBYTE lpb;
PGETRAWINPUTDATA pGetRawInputData;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pGetRawInputData = ( PGETRAWINPUTDATA ) GetProcAddress( hUser32, "GetRawInputData" );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_INPUT, NULL, &dwSize,
sizeof( RAWINPUTHEADER ) );
lpb = ( LPBYTE ) hb_xgrab( dwSize );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_INPUT, lpb, &dwSize,
sizeof( RAWINPUTHEADER ) );
hb_retnl( ( unsigned long ) lpb );
FreeLibrary( hUser32 );
}
#pragma ENDDUMP
// Windows Raw Input API support demo, (c) FiveTech Software
#include "FiveWin.ch"
#define WM_INPUT 0x00FF
function Main()
local aHIDevices := GetRawInputDeviceList()
MsgSelect( aHIDevices, "", "Human Interface Devices" )
/*
local oWnd := TMyWindow():New()
oWnd:SetText( "Raw Input test" )
MsgInfo( RegisterRawInputDevices( oWnd:hWnd ) )
oWnd:Activate()
*/
return nil
function MsgSelect( aItems, cValue, cTitle )
local oDlg
DEFAULT cTitle := "Please, select"
DEFINE DIALOG oDlg FROM 5,10 TO 24, 80 TITLE cTitle
@ 0.5, 0.7 LISTBOX cValue ITEMS aItems SIZE 268, 110 OF oDlg
@ 7, 14 BUTTON "&OK" OF oDlg SIZE 40, 12 ;
ACTION oDlg:End() DEFAULT
@ 7, 24 BUTTON "&Cancel" OF oDlg SIZE 40, 12 ;
ACTION ( cValue := nil, oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED
return cValue
CLASS TMyWindow FROM TWindow
CLASSDATA lRegistered
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyWindow
if nMsg == WM_INPUT
MsgBeep() // ok, we are receiving WM_INPUT messages
endif
return Super:HandleEvent( nMsg, nWParam, nLParam )
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#define RIDEV_INPUTSINK 0x00000100
#define RID_INPUT 0x10000003
#define RIDI_DEVICENAME 0x20000007
typedef struct tagRAWINPUTDEVICE
{
USHORT usUsagePage;
USHORT usUsage;
DWORD dwFlags;
HWND hwndTarget;
} RAWINPUTDEVICE, * PRAWINPUTDEVICE, * LPRAWINPUTDEVICE;
typedef BOOL WINAPI ( * PREGISTERRAWINPUTDEVICES ) (
PRAWINPUTDEVICE pRawInputDevices,
UINT uiNumDevices,
UINT cbSize
);
typedef struct tagRAWINPUTHEADER {
DWORD dwType;
DWORD dwSize;
HANDLE hDevice;
WPARAM wParam;
} RAWINPUTHEADER, * PRAWINPUTHEADER;
typedef struct tagRAWMOUSE {
USHORT usFlags;
union {
ULONG ulButtons;
struct {
USHORT usButtonFlags;
USHORT usButtonData;
};
};
ULONG ulRawButtons;
LONG lLastX;
LONG lLastY;
ULONG ulExtraInformation;
} RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;
typedef struct tagRAWKEYBOARD {
USHORT MakeCode;
USHORT Flags;
USHORT Reserved;
USHORT VKey;
UINT Message;
ULONG ExtraInformation;
} RAWKEYBOARD, *PRAWKEYBOARD, *LPRAWKEYBOARD;
typedef struct tagRAWHID {
DWORD dwSizeHid;
DWORD dwCount;
BYTE bRawData;
} RAWHID, **LPRAWHID;
typedef struct tagRAWINPUT {
RAWINPUTHEADER header;
union {
RAWMOUSE mouse;
RAWKEYBOARD keyboard;
RAWHID hid;
} data;
} RAWINPUT, * PRAWINPUT, * LPRAWINPUT;
typedef UINT WINAPI ( * PGETRAWINPUTDATA ) (
LPRAWINPUT hRawInput,
UINT uiCommand,
LPVOID pData,
PUINT pcbSize,
UINT cbSizeHeader
);
typedef struct tagRAWINPUTDEVICELIST {
HANDLE hDevice;
DWORD dwType;
} RAWINPUTDEVICELIST, * PRAWINPUTDEVICELIST;
typedef UINT WINAPI ( * PGETRAWINPUTDEVICELIST ) (
PRAWINPUTDEVICELIST pRawInputDeviceList,
PUINT puiNumDevices,
UINT cbSize
);
typedef UINT WINAPI ( * PGETRAWINPUTDEVICEINFO ) (
HANDLE hDevice,
UINT uiCommand,
LPVOID pData,
PUINT pcbSize
);
HB_FUNC( REGISTERRAWINPUTDEVICES )
{
RAWINPUTDEVICE rid[ 2 ];
PREGISTERRAWINPUTDEVICES pRegisterRawInputDevices;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pRegisterRawInputDevices = ( PREGISTERRAWINPUTDEVICES ) GetProcAddress( hUser32, "RegisterRawInputDevices" );
rid[ 0 ].usUsagePage = 0x01;
rid[ 0 ].usUsage = 0x02; // Mouse
rid[ 0 ].dwFlags = RIDEV_INPUTSINK;
rid[ 0 ].hwndTarget = ( HWND ) hb_parnl( 1 );
rid[ 1 ].usUsagePage = 0x01;
rid[ 1 ].usUsage = 0x06; // Keyboard
rid[ 1 ].dwFlags = RIDEV_INPUTSINK;
rid[ 1 ].hwndTarget = ( HWND ) hb_parnl( 1 );
hb_retl( pRegisterRawInputDevices( rid, 2, sizeof( RAWINPUTDEVICE ) ) );
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWINPUTDATA )
{
UINT dwSize;
LPBYTE lpb;
PGETRAWINPUTDATA pGetRawInputData;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pGetRawInputData = ( PGETRAWINPUTDATA ) GetProcAddress( hUser32, "GetRawInputData" );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_INPUT, NULL, &dwSize,
sizeof( RAWINPUTHEADER ) );
lpb = ( LPBYTE ) hb_xgrab( dwSize );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_INPUT, lpb, &dwSize,
sizeof( RAWINPUTHEADER ) );
hb_retnl( ( unsigned long ) lpb );
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWINPUTDEVICELIST )
{
UINT nDevices;
PRAWINPUTDEVICELIST pRawInputDeviceList;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
PGETRAWINPUTDEVICELIST pGetRawInputDeviceList;
PGETRAWINPUTDEVICEINFO pGetRawInputDeviceInfo;
pGetRawInputDeviceList = ( PGETRAWINPUTDEVICELIST ) GetProcAddress( hUser32, "GetRawInputDeviceList" );
pGetRawInputDeviceInfo = ( PGETRAWINPUTDEVICEINFO ) GetProcAddress( hUser32, "GetRawInputDeviceInfoA" );
pGetRawInputDeviceList( NULL, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
if( nDevices )
{
UINT ui;
pRawInputDeviceList = ( PRAWINPUTDEVICELIST ) hb_xgrab( sizeof( RAWINPUTDEVICELIST ) * nDevices );
pGetRawInputDeviceList( pRawInputDeviceList, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
hb_reta( nDevices );
for( ui = 0; ui < nDevices; ui++ )
{
char name[ 512 ];
UINT uiSize = 511;
pGetRawInputDeviceInfo( pRawInputDeviceList[ ui ].hDevice, RIDI_DEVICENAME, ( void * ) name, &uiSize );
hb_storclen( name, uiSize, -1, ui + 1 );
}
hb_xfree( ( void * ) pRawInputDeviceList );
}
FreeLibrary( hUser32 );
}
#pragma ENDDUMP
// Windows Raw Input API support demo, (c) FiveTech Software
#include "FiveWin.ch"
#define WM_INPUT 0x00FF
function Main()
local nMouses := GetRawMouses(), n
MsgInfo( "Number of available mouses: " + AllTrim( Str( nMouses ) ) )
for n = 1 to nMouses
MsgInfo( GetRawMouse( n ), "Mouse " + AllTrim( Str( n ) ) )
next
/*
local oWnd := TMyWindow():New()
oWnd:SetText( "Raw Input test" )
MsgInfo( RegisterRawInputDevices( oWnd:hWnd ) )
oWnd:Activate()
*/
return nil
function MsgSelect( aItems, cValue, cTitle )
local oDlg
DEFAULT cTitle := "Please, select"
DEFINE DIALOG oDlg FROM 5,10 TO 24, 80 TITLE cTitle
@ 0.5, 0.7 LISTBOX cValue ITEMS aItems SIZE 268, 110 OF oDlg
@ 7, 14 BUTTON "&OK" OF oDlg SIZE 40, 12 ;
ACTION oDlg:End() DEFAULT
@ 7, 24 BUTTON "&Cancel" OF oDlg SIZE 40, 12 ;
ACTION ( cValue := nil, oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED
return cValue
CLASS TMyWindow FROM TWindow
CLASSDATA lRegistered
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyWindow
if nMsg == WM_INPUT
MsgBeep() // ok, we are receiving WM_INPUT messages
endif
return Super:HandleEvent( nMsg, nWParam, nLParam )
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#define RIDEV_INPUTSINK 0x00000100
#define RID_INPUT 0x10000003
#define RIDI_DEVICENAME 0x20000007
#define RIDI_DEVICEINFO 0x2000000b
#define RIM_TYPEMOUSE 0
#define RIM_TYPEKEYBOARD 1
#define RIM_TYPEHID 2
typedef struct tagRAWINPUTDEVICE
{
USHORT usUsagePage;
USHORT usUsage;
DWORD dwFlags;
HWND hwndTarget;
} RAWINPUTDEVICE, * PRAWINPUTDEVICE, * LPRAWINPUTDEVICE;
typedef BOOL WINAPI ( * PREGISTERRAWINPUTDEVICES ) (
PRAWINPUTDEVICE pRawInputDevices,
UINT uiNumDevices,
UINT cbSize
);
typedef struct tagRAWINPUTHEADER {
DWORD dwType;
DWORD dwSize;
HANDLE hDevice;
WPARAM wParam;
} RAWINPUTHEADER, * PRAWINPUTHEADER;
typedef struct tagRAWMOUSE {
USHORT usFlags;
union {
ULONG ulButtons;
struct {
USHORT usButtonFlags;
USHORT usButtonData;
};
};
ULONG ulRawButtons;
LONG lLastX;
LONG lLastY;
ULONG ulExtraInformation;
} RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;
typedef struct tagRAWKEYBOARD {
USHORT MakeCode;
USHORT Flags;
USHORT Reserved;
USHORT VKey;
UINT Message;
ULONG ExtraInformation;
} RAWKEYBOARD, *PRAWKEYBOARD, *LPRAWKEYBOARD;
typedef struct tagRAWHID {
DWORD dwSizeHid;
DWORD dwCount;
BYTE bRawData;
} RAWHID, **LPRAWHID;
typedef struct tagRAWINPUT {
RAWINPUTHEADER header;
union {
RAWMOUSE mouse;
RAWKEYBOARD keyboard;
RAWHID hid;
} data;
} RAWINPUT, * PRAWINPUT, * LPRAWINPUT;
typedef UINT WINAPI ( * PGETRAWINPUTDATA ) (
LPRAWINPUT hRawInput,
UINT uiCommand,
LPVOID pData,
PUINT pcbSize,
UINT cbSizeHeader
);
typedef struct tagRAWINPUTDEVICELIST {
HANDLE hDevice;
DWORD dwType;
} RAWINPUTDEVICELIST, * PRAWINPUTDEVICELIST;
typedef UINT WINAPI ( * PGETRAWINPUTDEVICELIST ) (
PRAWINPUTDEVICELIST pRawInputDeviceList,
PUINT puiNumDevices,
UINT cbSize
);
typedef struct tagRID_DEVICE_INFO_MOUSE {
DWORD dwId;
DWORD dwNumberOfButtons;
DWORD dwSampleRate;
BOOL fHasHorizontalWheel;
} RID_DEVICE_INFO_MOUSE, * PRID_DEVICE_INFO_MOUSE;
typedef struct tagRID_DEVICE_INFO_KEYBOARD {
DWORD dwType;
DWORD dwSubType;
DWORD dwKeyboardMode;
DWORD dwNumberOfFunctionKeys;
DWORD dwNumberOfIndicators;
DWORD dwNumberOfKeysTotal;
} RID_DEVICE_INFO_KEYBOARD, * PRID_DEVICE_INFO_KEYBOARD;
typedef struct tagRID_DEVICE_INFO_HID {
DWORD dwVendorId;
DWORD dwProductId;
DWORD dwVersionNumber;
USHORT usUsagePage;
USHORT usUsage;
} RID_DEVICE_INFO_HID, * PRID_DEVICE_INFO_HID;
typedef struct tagRID_DEVICE_INFO {
DWORD cbSize;
DWORD dwType;
union {
RID_DEVICE_INFO_MOUSE mouse;
RID_DEVICE_INFO_KEYBOARD keyboard;
RID_DEVICE_INFO_HID hid;
};
} RID_DEVICE_INFO, * PRID_DEVICE_INFO, * LPRID_DEVICE_INFO;
typedef UINT WINAPI ( * PGETRAWINPUTDEVICEINFO ) (
HANDLE hDevice,
UINT uiCommand,
LPVOID pData,
PUINT pcbSize
);
HB_FUNC( REGISTERRAWINPUTDEVICES )
{
RAWINPUTDEVICE rid[ 2 ];
PREGISTERRAWINPUTDEVICES pRegisterRawInputDevices;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pRegisterRawInputDevices = ( PREGISTERRAWINPUTDEVICES ) GetProcAddress( hUser32, "RegisterRawInputDevices" );
rid[ 0 ].usUsagePage = 0x01;
rid[ 0 ].usUsage = 0x02; // Mouse
rid[ 0 ].dwFlags = RIDEV_INPUTSINK;
rid[ 0 ].hwndTarget = ( HWND ) hb_parnl( 1 );
rid[ 1 ].usUsagePage = 0x01;
rid[ 1 ].usUsage = 0x06; // Keyboard
rid[ 1 ].dwFlags = RIDEV_INPUTSINK;
rid[ 1 ].hwndTarget = ( HWND ) hb_parnl( 1 );
hb_retl( pRegisterRawInputDevices( rid, 2, sizeof( RAWINPUTDEVICE ) ) );
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWINPUTDATA )
{
UINT dwSize;
LPBYTE lpb;
PGETRAWINPUTDATA pGetRawInputData;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pGetRawInputData = ( PGETRAWINPUTDATA ) GetProcAddress( hUser32, "GetRawInputData" );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_INPUT, NULL, &dwSize,
sizeof( RAWINPUTHEADER ) );
lpb = ( LPBYTE ) hb_xgrab( dwSize );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_INPUT, lpb, &dwSize,
sizeof( RAWINPUTHEADER ) );
hb_retnl( ( unsigned long ) lpb );
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWINPUTDEVICELIST )
{
UINT nDevices;
PRAWINPUTDEVICELIST pRawInputDeviceList;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
PGETRAWINPUTDEVICELIST pGetRawInputDeviceList;
PGETRAWINPUTDEVICEINFO pGetRawInputDeviceInfo;
pGetRawInputDeviceList = ( PGETRAWINPUTDEVICELIST ) GetProcAddress( hUser32, "GetRawInputDeviceList" );
pGetRawInputDeviceInfo = ( PGETRAWINPUTDEVICEINFO ) GetProcAddress( hUser32, "GetRawInputDeviceInfoA" );
pGetRawInputDeviceList( NULL, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
if( nDevices )
{
UINT ui;
pRawInputDeviceList = ( PRAWINPUTDEVICELIST ) hb_xgrab( sizeof( RAWINPUTDEVICELIST ) * nDevices );
pGetRawInputDeviceList( pRawInputDeviceList, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
hb_reta( nDevices );
for( ui = 0; ui < nDevices; ui++ )
{
char name[ 512 ];
UINT uiSize = 511;
pGetRawInputDeviceInfo( pRawInputDeviceList[ ui ].hDevice, RIDI_DEVICENAME, ( void * ) name, &uiSize );
hb_storclen( name, uiSize, -1, ui + 1 );
}
hb_xfree( ( void * ) pRawInputDeviceList );
}
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWMOUSE ) // nMouse --> hDevice
{
UINT nDevices;
PRAWINPUTDEVICELIST pRawInputDeviceList;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
PGETRAWINPUTDEVICELIST pGetRawInputDeviceList;
PGETRAWINPUTDEVICEINFO pGetRawInputDeviceInfo;
pGetRawInputDeviceList = ( PGETRAWINPUTDEVICELIST ) GetProcAddress( hUser32, "GetRawInputDeviceList" );
pGetRawInputDeviceInfo = ( PGETRAWINPUTDEVICEINFO ) GetProcAddress( hUser32, "GetRawInputDeviceInfoA" );
pGetRawInputDeviceList( NULL, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
if( nDevices )
{
UINT ui;
UINT uiMouses = 0;
pRawInputDeviceList = ( PRAWINPUTDEVICELIST ) hb_xgrab( sizeof( RAWINPUTDEVICELIST ) * nDevices );
pGetRawInputDeviceList( pRawInputDeviceList, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
for( ui = 0; ui < nDevices; ui++ )
{
RID_DEVICE_INFO rdi;
UINT uiSize = sizeof( RID_DEVICE_INFO );
UINT uiMouse = hb_parnl( 1 );
rdi.cbSize = sizeof( RID_DEVICE_INFO );
pGetRawInputDeviceInfo( pRawInputDeviceList[ ui ].hDevice, RIDI_DEVICEINFO, ( void * ) &rdi, &uiSize );
if( rdi.dwType == RIM_TYPEMOUSE )
{
if( ++uiMouses == uiMouse )
{
hb_retnl( ( unsigned long ) pRawInputDeviceList[ ui ].hDevice );
hb_xfree( ( void * ) pRawInputDeviceList );
return;
}
}
}
hb_retnl( 0 );
hb_xfree( ( void * ) pRawInputDeviceList );
}
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWMOUSES ) // --> nMouses
{
UINT nDevices;
PRAWINPUTDEVICELIST pRawInputDeviceList;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
PGETRAWINPUTDEVICELIST pGetRawInputDeviceList;
PGETRAWINPUTDEVICEINFO pGetRawInputDeviceInfo;
UINT uiMouses = 0;
pGetRawInputDeviceList = ( PGETRAWINPUTDEVICELIST ) GetProcAddress( hUser32, "GetRawInputDeviceList" );
pGetRawInputDeviceInfo = ( PGETRAWINPUTDEVICEINFO ) GetProcAddress( hUser32, "GetRawInputDeviceInfoA" );
pGetRawInputDeviceList( NULL, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
if( nDevices )
{
UINT ui;
pRawInputDeviceList = ( PRAWINPUTDEVICELIST ) hb_xgrab( sizeof( RAWINPUTDEVICELIST ) * nDevices );
pGetRawInputDeviceList( pRawInputDeviceList, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
for( ui = 0; ui < nDevices; ui++ )
{
RID_DEVICE_INFO rdi;
UINT uiSize = sizeof( RID_DEVICE_INFO );
rdi.cbSize = sizeof( RID_DEVICE_INFO );
pGetRawInputDeviceInfo( pRawInputDeviceList[ ui ].hDevice, RIDI_DEVICEINFO, ( void * ) &rdi, &uiSize );
if( rdi.dwType == RIM_TYPEMOUSE )
uiMouses++;
}
hb_xfree( ( void * ) pRawInputDeviceList );
}
hb_retnl( --uiMouses ); // Windows reports an extra mouse (?)
FreeLibrary( hUser32 );
}
#pragma ENDDUMP
// Windows Raw Input API support demo, (c) FiveTech Software
#include "FiveWin.ch"
#define WM_INPUT 0x00FF
function Main()
local oWnd := TMyWindow():New()
oWnd:SetText( "Raw Input test" )
oWnd:hMouse = GetRawMouse( 2 ) // Use mouse 2 only
RegisterRawInputDevices( oWnd:hWnd )
oWnd:Activate()
return nil
CLASS TMyWindow FROM TWindow
CLASSDATA lRegistered
DATA hMouse // handle of the mouse to use
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyWindow
if nMsg == WM_INPUT
if RawIsMouse( nLParam ) .and. RawGetHandle( nLParam ) == ::hMouse
// MsgBeep()
LogFile( "rawinput.txt", { RawIsMouse( nLParam ), RawGetHandle( nLParam ), ::hMouse } )
endif
endif
return Super:HandleEvent( nMsg, nWParam, nLParam )
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#define RIDEV_INPUTSINK 0x00000100
#define RID_INPUT 0x10000003
#define RID_HEADER 0x10000005
#define RIDI_DEVICENAME 0x20000007
#define RIDI_DEVICEINFO 0x2000000b
#define RIM_TYPEMOUSE 0
#define RIM_TYPEKEYBOARD 1
#define RIM_TYPEHID 2
typedef struct tagRAWINPUTDEVICE
{
USHORT usUsagePage;
USHORT usUsage;
DWORD dwFlags;
HWND hwndTarget;
} RAWINPUTDEVICE, * PRAWINPUTDEVICE, * LPRAWINPUTDEVICE;
typedef BOOL WINAPI ( * PREGISTERRAWINPUTDEVICES ) (
PRAWINPUTDEVICE pRawInputDevices,
UINT uiNumDevices,
UINT cbSize
);
typedef struct tagRAWINPUTHEADER {
DWORD dwType;
DWORD dwSize;
HANDLE hDevice;
WPARAM wParam;
} RAWINPUTHEADER, * PRAWINPUTHEADER;
typedef struct tagRAWMOUSE {
USHORT usFlags;
union {
ULONG ulButtons;
struct {
USHORT usButtonFlags;
USHORT usButtonData;
};
};
ULONG ulRawButtons;
LONG lLastX;
LONG lLastY;
ULONG ulExtraInformation;
} RAWMOUSE, * PRAWMOUSE, * LPRAWMOUSE;
typedef struct tagRAWKEYBOARD {
USHORT MakeCode;
USHORT Flags;
USHORT Reserved;
USHORT VKey;
UINT Message;
ULONG ExtraInformation;
} RAWKEYBOARD, *PRAWKEYBOARD, *LPRAWKEYBOARD;
typedef struct tagRAWHID {
DWORD dwSizeHid;
DWORD dwCount;
BYTE bRawData;
} RAWHID, **LPRAWHID;
typedef struct tagRAWINPUT {
RAWINPUTHEADER header;
union {
RAWMOUSE mouse;
RAWKEYBOARD keyboard;
RAWHID hid;
} data;
} RAWINPUT, * PRAWINPUT, * LPRAWINPUT;
typedef UINT WINAPI ( * PGETRAWINPUTDATA ) (
LPRAWINPUT hRawInput,
UINT uiCommand,
LPVOID pData,
PUINT pcbSize,
UINT cbSizeHeader
);
typedef struct tagRAWINPUTDEVICELIST {
HANDLE hDevice;
DWORD dwType;
} RAWINPUTDEVICELIST, * PRAWINPUTDEVICELIST;
typedef UINT WINAPI ( * PGETRAWINPUTDEVICELIST ) (
PRAWINPUTDEVICELIST pRawInputDeviceList,
PUINT puiNumDevices,
UINT cbSize
);
typedef struct tagRID_DEVICE_INFO_MOUSE {
DWORD dwId;
DWORD dwNumberOfButtons;
DWORD dwSampleRate;
BOOL fHasHorizontalWheel;
} RID_DEVICE_INFO_MOUSE, * PRID_DEVICE_INFO_MOUSE;
typedef struct tagRID_DEVICE_INFO_KEYBOARD {
DWORD dwType;
DWORD dwSubType;
DWORD dwKeyboardMode;
DWORD dwNumberOfFunctionKeys;
DWORD dwNumberOfIndicators;
DWORD dwNumberOfKeysTotal;
} RID_DEVICE_INFO_KEYBOARD, * PRID_DEVICE_INFO_KEYBOARD;
typedef struct tagRID_DEVICE_INFO_HID {
DWORD dwVendorId;
DWORD dwProductId;
DWORD dwVersionNumber;
USHORT usUsagePage;
USHORT usUsage;
} RID_DEVICE_INFO_HID, * PRID_DEVICE_INFO_HID;
typedef struct tagRID_DEVICE_INFO {
DWORD cbSize;
DWORD dwType;
union {
RID_DEVICE_INFO_MOUSE mouse;
RID_DEVICE_INFO_KEYBOARD keyboard;
RID_DEVICE_INFO_HID hid;
};
} RID_DEVICE_INFO, * PRID_DEVICE_INFO, * LPRID_DEVICE_INFO;
typedef UINT WINAPI ( * PGETRAWINPUTDEVICEINFO ) (
HANDLE hDevice,
UINT uiCommand,
LPVOID pData,
PUINT pcbSize
);
HB_FUNC( REGISTERRAWINPUTDEVICES )
{
RAWINPUTDEVICE rid[ 2 ];
PREGISTERRAWINPUTDEVICES pRegisterRawInputDevices;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pRegisterRawInputDevices = ( PREGISTERRAWINPUTDEVICES ) GetProcAddress( hUser32, "RegisterRawInputDevices" );
rid[ 0 ].usUsagePage = 0x01;
rid[ 0 ].usUsage = 0x02; // Mouse
rid[ 0 ].dwFlags = RIDEV_INPUTSINK;
rid[ 0 ].hwndTarget = ( HWND ) hb_parnl( 1 );
rid[ 1 ].usUsagePage = 0x01;
rid[ 1 ].usUsage = 0x06; // Keyboard
rid[ 1 ].dwFlags = RIDEV_INPUTSINK;
rid[ 1 ].hwndTarget = ( HWND ) hb_parnl( 1 );
hb_retl( pRegisterRawInputDevices( rid, 2, sizeof( RAWINPUTDEVICE ) ) );
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWINPUTDATA )
{
UINT dwSize;
LPBYTE lpb;
PGETRAWINPUTDATA pGetRawInputData;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pGetRawInputData = ( PGETRAWINPUTDATA ) GetProcAddress( hUser32, "GetRawInputData" );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_INPUT, NULL, &dwSize,
sizeof( RAWINPUTHEADER ) );
lpb = ( LPBYTE ) hb_xgrab( dwSize );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_INPUT, lpb, &dwSize,
sizeof( RAWINPUTHEADER ) );
hb_retnl( ( unsigned long ) lpb );
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWINPUTDEVICELIST )
{
UINT nDevices;
PRAWINPUTDEVICELIST pRawInputDeviceList;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
PGETRAWINPUTDEVICELIST pGetRawInputDeviceList;
PGETRAWINPUTDEVICEINFO pGetRawInputDeviceInfo;
pGetRawInputDeviceList = ( PGETRAWINPUTDEVICELIST ) GetProcAddress( hUser32, "GetRawInputDeviceList" );
pGetRawInputDeviceInfo = ( PGETRAWINPUTDEVICEINFO ) GetProcAddress( hUser32, "GetRawInputDeviceInfoA" );
pGetRawInputDeviceList( NULL, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
if( nDevices )
{
UINT ui;
pRawInputDeviceList = ( PRAWINPUTDEVICELIST ) hb_xgrab( sizeof( RAWINPUTDEVICELIST ) * nDevices );
pGetRawInputDeviceList( pRawInputDeviceList, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
hb_reta( nDevices );
for( ui = 0; ui < nDevices; ui++ )
{
char name[ 512 ];
UINT uiSize = 511;
pGetRawInputDeviceInfo( pRawInputDeviceList[ ui ].hDevice, RIDI_DEVICENAME, ( void * ) name, &uiSize );
hb_storclen( name, uiSize, -1, ui + 1 );
}
hb_xfree( ( void * ) pRawInputDeviceList );
}
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWMOUSE ) // nMouse --> hDevice
{
UINT nDevices;
PRAWINPUTDEVICELIST pRawInputDeviceList;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
PGETRAWINPUTDEVICELIST pGetRawInputDeviceList;
PGETRAWINPUTDEVICEINFO pGetRawInputDeviceInfo;
pGetRawInputDeviceList = ( PGETRAWINPUTDEVICELIST ) GetProcAddress( hUser32, "GetRawInputDeviceList" );
pGetRawInputDeviceInfo = ( PGETRAWINPUTDEVICEINFO ) GetProcAddress( hUser32, "GetRawInputDeviceInfoA" );
pGetRawInputDeviceList( NULL, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
if( nDevices )
{
UINT ui;
UINT uiMouses = 0;
pRawInputDeviceList = ( PRAWINPUTDEVICELIST ) hb_xgrab( sizeof( RAWINPUTDEVICELIST ) * nDevices );
pGetRawInputDeviceList( pRawInputDeviceList, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
for( ui = 0; ui < nDevices; ui++ )
{
RID_DEVICE_INFO rdi;
UINT uiSize = sizeof( RID_DEVICE_INFO );
UINT uiMouse = hb_parnl( 1 );
rdi.cbSize = sizeof( RID_DEVICE_INFO );
pGetRawInputDeviceInfo( pRawInputDeviceList[ ui ].hDevice, RIDI_DEVICEINFO, ( void * ) &rdi, &uiSize );
if( rdi.dwType == RIM_TYPEMOUSE )
{
if( ++uiMouses == uiMouse )
{
hb_retnl( ( unsigned long ) pRawInputDeviceList[ ui ].hDevice );
hb_xfree( ( void * ) pRawInputDeviceList );
return;
}
}
}
hb_retnl( 0 );
hb_xfree( ( void * ) pRawInputDeviceList );
}
FreeLibrary( hUser32 );
}
HB_FUNC( GETRAWMOUSES ) // --> nMouses
{
UINT nDevices;
PRAWINPUTDEVICELIST pRawInputDeviceList;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
PGETRAWINPUTDEVICELIST pGetRawInputDeviceList;
PGETRAWINPUTDEVICEINFO pGetRawInputDeviceInfo;
UINT uiMouses = 0;
pGetRawInputDeviceList = ( PGETRAWINPUTDEVICELIST ) GetProcAddress( hUser32, "GetRawInputDeviceList" );
pGetRawInputDeviceInfo = ( PGETRAWINPUTDEVICEINFO ) GetProcAddress( hUser32, "GetRawInputDeviceInfoA" );
pGetRawInputDeviceList( NULL, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
if( nDevices )
{
UINT ui;
pRawInputDeviceList = ( PRAWINPUTDEVICELIST ) hb_xgrab( sizeof( RAWINPUTDEVICELIST ) * nDevices );
pGetRawInputDeviceList( pRawInputDeviceList, &nDevices, sizeof( RAWINPUTDEVICELIST ) );
for( ui = 0; ui < nDevices; ui++ )
{
RID_DEVICE_INFO rdi;
UINT uiSize = sizeof( RID_DEVICE_INFO );
rdi.cbSize = sizeof( RID_DEVICE_INFO );
pGetRawInputDeviceInfo( pRawInputDeviceList[ ui ].hDevice, RIDI_DEVICEINFO, ( void * ) &rdi, &uiSize );
if( rdi.dwType == RIM_TYPEMOUSE )
uiMouses++;
}
hb_xfree( ( void * ) pRawInputDeviceList );
}
hb_retnl( --uiMouses ); // Windows reports an extra mouse (?)
FreeLibrary( hUser32 );
}
HB_FUNC( RAWISMOUSE )
{
LPRAWINPUT pri = ( LPRAWINPUT ) hb_parnl( 1 );
UINT dwSize;
LPBYTE lpb;
PGETRAWINPUTDATA pGetRawInputData;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pGetRawInputData = ( PGETRAWINPUTDATA ) GetProcAddress( hUser32, "GetRawInputData" );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_HEADER, NULL, &dwSize,
sizeof( RAWINPUTHEADER ) );
lpb = ( LPBYTE ) hb_xgrab( dwSize );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_HEADER, lpb, &dwSize,
sizeof( RAWINPUTHEADER ) );
hb_retl( ( ( PRAWINPUTHEADER ) lpb )->dwType == RIM_TYPEMOUSE );
hb_xfree( ( void * ) lpb );
FreeLibrary( hUser32 );
}
HB_FUNC( RAWGETHANDLE )
{
LPRAWINPUT pri = ( LPRAWINPUT ) hb_parnl( 1 );
UINT dwSize;
LPBYTE lpb;
PGETRAWINPUTDATA pGetRawInputData;
HINSTANCE hUser32 = LoadLibrary( "user32.dll" );
pGetRawInputData = ( PGETRAWINPUTDATA ) GetProcAddress( hUser32, "GetRawInputData" );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_HEADER, NULL, &dwSize,
sizeof( RAWINPUTHEADER ) );
lpb = ( LPBYTE ) hb_xgrab( dwSize );
pGetRawInputData( ( LPRAWINPUT ) hb_parnl( 1 ), RID_HEADER, lpb, &dwSize,
sizeof( RAWINPUTHEADER ) );
hb_retnl( ( unsigned long ) ( ( PRAWINPUTHEADER ) lpb )->hDevice );
hb_xfree( ( void * ) lpb );
FreeLibrary( hUser32 );
}
#pragma ENDDUMP
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 68 guests