Jump to content

Recommended Posts

Posted (edited)

Okay well using a combination of hdevice and vendorid I've managed to identify all functions of the remote.

Now just one problem, my keyboard works fine in all applications while the script is running.

BUT when I have the script prompt me for input, such as a GUI InputBox or standard InputBox()

Nothing I type is recognized.

I've been playing with it for an hour with no luck, I was hoping you might have an idea.

;===================================================================

I'm attaching the script for you to try. I've commented out the action that locks the computer.

There is nothing that will make any changes to your machine.

You can hit F9 to exit the script.

To test:

1) Run the script (duh lol)

2) hit something on your keyboard, you'll get a msgbox "locked"

3) hit F12 you'll be given an input box, the password is 0000. But your keyboard won't work

To troubleshoot comment out line 154 ($PassPrompt = 1).

You will then be able to turn the lock feature on and off without the password prompt.

Thanks,

Kenny

;#include <AdlibHandler.au3>
#include <RawInput.au3>
;==============================
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

HotKeySet('{F9}', '_EXIT')

#Region Initialize Global Variables
Global $Password   = "0000"
Global $RunToggle  = 1
Global $PassPrompt = 0
Global $Locked   = 0
#EndRegion

#Region Enable Adlib Functions
;AdlibEnable("_Adlib_Handler", 20)
;_Adlib_AddFunction("IsScreenLocked", "", 20)
;_Adlib_AddFunction("PasswordPrompt", "", 20)
AdlibEnable("PasswordPrompt", 20)
#EndRegion

#Region Initalize HID Monitoring
Global $tRID_KD, $pRID_KD, $iRID_KD
Global $tRIH, $pRIH, $iRIH
Global $iNumDevices
Global $hGUI , $pData
$hGUI = GUICreate('Test', 100, 100)
GUIRegisterMsg($WM_INPUT, 'OnInput')
$tRID_KD = DllStructCreate($tagRAWINPUTDEVICE)
$pRID_KD = DllStructGetPtr($tRID_KD)
$iRID_KD = DllStructGetSize($tRID_KD)
$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$pRIH = DllStructGetPtr($tRIH)
$iRIH = DllStructGetSize($tRIH)
$iNumDevices = 1
DllStructSetData($tRID_KD, 'usUsagePage', 0x01)
DllStructSetData($tRID_KD, 'usUsage', 0x06)
DllStructSetData($tRID_KD, 'dwFlags', BitOR($RIDEV_NOLEGACY, $RIDEV_INPUTSINK))
DllStructSetData($tRID_KD, 'hwndTarget', $hGUI)
_RegisterRawInputDevices($pRID_KD, $iNumDevices, $iRID_KD)
#EndRegion




While 1
    Sleep(10)
    If $RunToggle = 1 Then
        If WinExists("Windows Task Manager") Then
            WinClose("Windows Task Manager")
            WinKill("Windows Task Manager")
        EndIf
        If WinExists("Start menu") Then
            WinClose("Start menu")
            WinKill("Start menu")
        EndIf
    EndIf
WEnd


#Region CUSTOM FUNCTIONS
Func _EXIT()
    GUIDelete()
    Exit
EndFunc

Func PasswordPrompt()
    If $PassPrompt = 0 Then Return 0
    $PassGUI   = GUICreate("Password", @DesktopWidth, @DesktopHeight + 100, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
    GUISetFont (11.5 , 600)
    GUICtrlCreateLabel("Please enter your passcode", @DesktopWidth/2 - 125, @DesktopHeight/2 - 30, 250, 25, $SS_CENTER)
    $PassInput = GUICtrlCreateInput("", @DesktopWidth/2 - 125, @DesktopHeight/2, 250, 25, BitOR($ES_CENTER, $ES_PASSWORD))
    $PassBTN   = GUICtrlCreateButton("OK", @DesktopWidth/2 - 120, @DesktopHeight/2 + 39, 100, 25, $BS_DEFPUSHBUTTON)
    $CancelBTN = GUICtrlCreateButton("Cancel", @DesktopWidth/2 + 20, @DesktopHeight/2 + 39, 100, 25)
    GUICtrlSetState($PassInput, $GUI_FOCUS)
    GUISetState(@SW_SHOW)
    While 1
        Sleep(100)
        $hMsg = GUIGetMsg()
        Switch $hMsg
            Case $PassBTN
                If GUICtrlRead($PassInput) = $Password Then
                    $PassPrompt = 0
                    $RunToggle  = 0
                    Return 0
                Else
                    SoundPlay(@WindowsDir & "\Media\Notify.wav")
                    ToolTip(@CR & @CR & @CR & "         The Password you have entered is invalid or incorrect.         " & @CR & @CR & @CR & " " & @CR, @DesktopWidth/2 - 135, @DesktopHeight/2 - 125, "Password Error", 3, 4)
                    Sleep(2500)
                    ToolTip("")
                    GUICtrlSetData($PassInput, "")
                    GUICtrlSetState($PassInput, $GUI_FOCUS)
                EndIf
            Case $CancelBTN
                GUISetState(@SW_HIDE)
                GUIDelete()
                $PassPrompt = 0
                $RunToggle  = 1
                Return 0
        EndSwitch
    WEnd

EndFunc

;Check if Windows is locked
Func IsScreenLocked()
    $hLocked = DllCall("user32.dll", "long", "OpenInputDesktop", "dword", 0, "dword", 0, "dword", 0x0040)
    If @error Then Exit
    If $hLocked[0] = 0 Then
        $Locked = 1
    Else
        If $Locked = 1 Then Sleep(2000)
        $Locked = 0
    EndIf
EndFunc ;==>ScreenLocked

;Process Keyboard Input
Func OnInput($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tRI_KD, $pRI_KD, $iRI_KB
    Local $tRIDI_HID, $pRIDI_HID, $iRIDI_HID
    Local $hDevice
   
    $tRI_KD = DllStructCreate($tagRAWINPUT_KEYBOARD)
    $pRI_KD = DllStructGetPtr($tRI_KD)
    $iRI_KB = DllStructGetSize($tRI_KD)
    
    $tRIDI_HID = DllStructCreate($tagRIDDEVICEINFO_HID)
    $pRIDI_HID = DllStructGetPtr($tRIDI_HID)
    $iRIDI_HID = DllStructGetSize($tRIDI_HID)
    DllStructSetData($tRIDI_HID, 'cbSize', $iRIDI_HID)

    _GetRawInputData($ilParam, $RID_INPUT, $pRI_KD, $iRI_KB, $iRIH)
    If Not @error Then
        $hDevice = DllStructGetData($tRI_KD, 'hDevice')
        $vKey    = DllStructGetData($tRI_KD, 'VKey');F3 = 114
    EndIf
    _GetRawInputDeviceInfo($hDevice, $RIDI_DEVICEINFO, $pRIDI_HID, $iRIDI_HID)
    If Not @error Then
         $hDevice2  = DllStructGetData($tRI_KD, 'hDevice')
        $dwVendorId  = DllStructGetData($tRIDI_HID, 'dwVendorId')
        $dwProductId = DllStructGetData($tRIDI_HID, 'dwProductId')
        $dwType   = DllStructGetData($tRI_KD, 'dwType')
    EndIf
    If $dwVendorId <> 81 AND $hDevice <> 0x00000000 AND $PassPrompt = 0 Then
        If $vKey = 123 Then
            If $RunToggle = 0 Then
                $RunToggle = 1
            Else
                $RunToggle  = 0
                $PassPrompt = 1
            EndIf
            Sleep(500)
        Else
    ;If $RunToggle = 1 AND $Locked = 0 Then Run("rundll32.exe user32.dll, LockWorkStation");lock computer
            MsgBox(0,"","Locking Computer")
        EndIf
    EndIf
   
    $tRI_KD = 0
    Return 'GUI_RUNDEFMSG'
EndFunc
#EndRegion
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

  • Replies 75
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted (edited)

It was intended so you'll not get double input events like $WM_KEYDOWN and $WM_INPUT for each keyboard input. If you want to get notified just change this line:

DllStructSetData($tRID_KD, 'dwFlags', BitOR($RIDEV_NOLEGACY, $RIDEV_INPUTSINK))

Edit: If you want, you can deregister the device thus not getting events from it while you're processing a managed input box or something you don't want to handle both in the $WM_INPUT and the GUI and reregister the device when you're done with the input box or the GUI.

Edited by Authenticity
Posted (edited)

Great, everything is working perfect! :)

Thanks for all your help with this, you must be worn out lol

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Posted

Yeah I'll clean it up a bit tonight.

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Posted

#Region Includes
#include <RawInput.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#EndRegion Includes

#Region Configure Hotkeys
HotKeySet('{F9}', '_EXIT')
#EndRegion Configure Hotkeys

#Region Initialize Global Variables
Global $Password   = "0000"
Global $RunToggle  = 1
Global $PassPrompt = 0
Global $Locked   = 0
;Required for RawInput.au3 Functions
Global $tRID_KD, $pRID_KD, $iRID_KD
Global $tRIH, $pRIH, $iRIH
Global $iNumDevices
Global $hGUI , $pData
#EndRegion Initialize Global Variables

#Region Enable Adlib Functions
;Monitor for windows locked status
AdlibEnable("IsScreenLocked", 20)
#EndRegion Enable Adlib Functions

#Region Initalize HID Device Monitoring
$hGUI = GUICreate('Test', 100, 100)
GUIRegisterMsg($WM_INPUT, 'OnInput')
$tRID_KD = DllStructCreate($tagRAWINPUTDEVICE)
$pRID_KD = DllStructGetPtr($tRID_KD)
$iRID_KD = DllStructGetSize($tRID_KD)
$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$pRIH = DllStructGetPtr($tRIH)
$iRIH = DllStructGetSize($tRIH)
$iNumDevices = 1
;Register Keyboard HID Devices
DllStructSetData($tRID_KD, 'usUsagePage', 0x01)
DllStructSetData($tRID_KD, 'usUsage', 0x06)
DllStructSetData($tRID_KD, 'dwFlags', $RIDEV_INPUTSINK)
DllStructSetData($tRID_KD, 'hwndTarget', $hGUI)
_RegisterRawInputDevices($pRID_KD, $iNumDevices, $iRID_KD)
;Register Mice HID Devices
DllStructSetData($tRID_KD, 'usUsagePage', 0x01)
DllStructSetData($tRID_KD, 'usUsage', 0x02)
DllStructSetData($tRID_KD, 'dwFlags', $RIDEV_INPUTSINK)
DllStructSetData($tRID_KD, 'hwndTarget', $hGUI)
_RegisterRawInputDevices($pRID_KD, $iNumDevices, $iRID_KD)
#EndRegion Initalize HID Device Monitoring

#Region Main Loop
While 1
    Sleep(10)
    If $RunToggle = 1 OR WinExists("PassGUI Unlock") Then;Don't run when "lockdown mode" is deactivated
        If WinExists("Windows Task Manager") Then
            WinClose("Windows Task Manager")
            WinKill("Windows Task Manager")
        EndIf
        If WinExists("Start menu") Then
            WinClose("Start menu")
            WinKill("Start menu")
        EndIf
    EndIf
WEnd
#EndRegion Main Loop


#Region ================================ USER DEFINED FUNCTIONS ================================
Func _EXIT()
    GUIDelete()
    Exit
EndFunc;==>_EXIT

Func IsScreenLocked();Check if Windows is locked
    $hLocked = DllCall("user32.dll", "long", "OpenInputDesktop", "dword", 0, "dword", 0, "dword", 0x0040)
    If @error Then Exit
    If $hLocked[0] = 0 Then
        $Locked = 1
    Else
        If $Locked = 1 Then Sleep(2000)
        $Locked = 0
    EndIf
EndFunc;==>IsScreenLocked

Func OnInput($hwnd, $iMsg, $iwParam, $ilParam);Process Keyboard Input from RawInput.au3 Commands
    Local $tRI_KD, $pRI_KD, $iRI_KB
    Local $tRIDI_HID, $pRIDI_HID, $iRIDI_HID
    Local $hDevice
;Prepare structure for keyboard info
    $tRI_KD = DllStructCreate($tagRAWINPUT_KEYBOARD)
    $pRI_KD = DllStructGetPtr($tRI_KD)
    $iRI_KB = DllStructGetSize($tRI_KD)
    
;Prepare structure for generic HID device info  
    $tRIDI_HID = DllStructCreate($tagRIDDEVICEINFO_HID)
    $pRIDI_HID = DllStructGetPtr($tRIDI_HID)
    $iRIDI_HID = DllStructGetSize($tRIDI_HID)
    DllStructSetData($tRIDI_HID, 'cbSize', $iRIDI_HID)
;Pull keyboard info
    _GetRawInputData($ilParam, $RID_INPUT, $pRI_KD, $iRI_KB, $iRIH)
    If Not @error Then
        $hDevice = DllStructGetData($tRI_KD, 'hDevice')
        $vKey    = DllStructGetData($tRI_KD, 'VKey');F3 = 114
    EndIf
;Prepare generic HID device info
    _GetRawInputDeviceInfo($hDevice, $RIDI_DEVICEINFO, $pRIDI_HID, $iRIDI_HID)
    If Not @error Then
         $hDevice2  = DllStructGetData($tRI_KD, 'hDevice')
        $dwVendorId  = DllStructGetData($tRIDI_HID, 'dwVendorId')
        $dwProductId = DllStructGetData($tRIDI_HID, 'dwProductId')
        $dwType   = DllStructGetData($tRI_KD, 'dwType')
    EndIf
    
;Process all input NOT recieved by remote
    If $dwVendorId <> 81 AND $hDevice <> 0x00000000 Then
        If $vKey = 123 Then;Toggle Lockdown Mode if F12 is hit
            If $RunToggle = 0 Then;If lockdown is deactivated, activate it
                $RunToggle = 1
            Else;If lockdown mode is activated temporaily deactivate and prompt for password.
                $RunToggle  = 0             
                $PassGUI   = GUICreate("PassGUI Unlock", @DesktopWidth, @DesktopHeight + 100, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
                WinSetTrans($PassGUI, "", 200)
                GUISetFont (11.5 , 600)
                GUICtrlCreateLabel("Please enter your passcode", @DesktopWidth/2 - 125, @DesktopHeight/2 - 30, 250, 25, $SS_CENTER)
                $PassInput = GUICtrlCreateInput("", @DesktopWidth/2 - 125, @DesktopHeight/2, 250, 25, BitOR($ES_CENTER, $ES_PASSWORD))
                $PassBTN   = GUICtrlCreateButton("OK", @DesktopWidth/2 - 120, @DesktopHeight/2 + 39, 100, 25, $BS_DEFPUSHBUTTON)
                $CancelBTN = GUICtrlCreateButton("Cancel", @DesktopWidth/2 + 20, @DesktopHeight/2 + 39, 100, 25)
                GUICtrlSetState($PassInput, $GUI_FOCUS)
                GUISetState(@SW_SHOW)
                While 1
                    Sleep(100)
                    $hMsg = GUIGetMsg()
                    Switch $hMsg
                        Case $PassBTN
                            If GUICtrlRead($PassInput) = $Password Then;If password is correct leave Lockdown Mode dactivated
                                GUISetState(@SW_HIDE)
                                GUIDelete()
                                $RunToggle  = 0
                                ExitLoop
                            Else;If password is incorrect advise user and prompt again.
                                SoundPlay(@WindowsDir & "\Media\Notify.wav")
                                ToolTip(@CR & @CR & @CR & "         The Password you have entered is invalid or incorrect.         " & @CR & @CR & @CR & " " & @CR, @DesktopWidth/2 - 135, @DesktopHeight/2 - 125, "Password Error", 3, 4)
                                Sleep(2500)
                                ToolTip("")
                                GUICtrlSetData($PassInput, "")
                                GUICtrlSetState($PassInput, $GUI_FOCUS)
                            EndIf
                        Case $CancelBTN;If password window is cancelled reactivate lockdown mode
                            GUISetState(@SW_HIDE)
                            GUIDelete()
                            $RunToggle  = 1
                            ExitLoop
                    EndSwitch
                WEnd
            EndIf
            Sleep(500)
        Else;If lockdown is active and mouse or keyboard is used lock computer
            If $RunToggle = 1 AND $Locked = 0 Then Run("rundll32.exe user32.dll, LockWorkStation")
        EndIf
    EndIf
   
    $tRI_KD = 0
    Return 'GUI_RUNDEFMSG'
EndFunc;==>OnInput
#EndRegion ============================== USER DEFINED FUNCTIONS ================================

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Posted

Sorry for ask againg but i'm associating with original TrystianSky request.

Is possibile to gain information from every HID compliant device ?

If yes, any possibility to obtain info also from game controller ?

(speak about xbox 360 gamepad)

Thank you for every reply,

m.

Posted (edited)

Hi, can you try this script and post the output of the handler, if it get called?

#include <RawInput.au3>
HotKeySet('{ESC}', '_EXIT')

Global $tRIDL, $pRIDL, $iRIDL, $tagRIDL
Global $tRIDI_HID, $pRIDI_HID, $iRIDI_HID
Global $tRID_HID, $pRID_HID, $iRID_HID
Global $tRIH, $pRIH, $iRIH
Global $iNumDevices
Global $hGUI


$hGUI = GUICreate('Test', 100, 100)
GUIRegisterMsg($WM_INPUT, 'OnInput')

$tRIDL = DllStructCreate($tagRAWINPUTDEVICELIST)
$iRIDL = DllStructGetSize($tRIDL)

$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$pRIH = DllStructGetPtr($tRIH)
$iRIH = DllStructGetSize($tRIH)

$iNumDevices = 0
_GetRawInputDeviceList(0, $iNumDevices, $iRIDL)
If @error Or $iNumDevices = 0 Then Exit
$tagRIDL = ''
For $i = 1 To $iNumDevices
    $tagRIDL &= StringRegExpReplace($tagRAWINPUTDEVICELIST, '(\w+);', '${1}' & $i & ';')
Next

$tRIDL = DllStructCreate($tagRIDL)
$pRIDL = DllStructGetPtr($tRIDL)
_GetRawInputDeviceList($pRIDL, $iNumDevices, $iRIDL)

If Not @error And $iNumDevices > 0  Then
    For $i = 1 To $iNumDevices
        If DllStructGetData($tRIDL, 'dwType') = $RIM_TYPEHID Then
            $tRIDI_HID = DllStructCreate($tagRIDDEVICEINFO_HID)
            $pRIDI_HID = DllStructGetPtr($tRIDI_HID)
            $iRIDI_HID = DllStructGetSize($tRIDI_HID)
            
            _GetRawInputDeviceInfo(DllStructGetData($tRIDL, 'hDevice' & $i), $RIDI_DEVICEINFO, $pRIDI_HID, $iRIDI_HID)
            If Not @error Then
                $tRID_HID = DllStructCreate($tagRAWINPUTDEVICE)
                $pRID_HID = DllStructGetPtr($tRID_HID)
                $iRID_HID = DllStructGetSize($tRID_HID)
                
                DllStructSetData($tRID_HID, 'usUsagePage', DllStructGetData($tRIDI_HID, 'usUsagePage'))
                DllStructSetData($tRID_HID, 'usUsage', DllStructGetData($tRIDI_HID, 'usUsage'))
                DllStructSetData($tRID_HID, 'dwFlags', BitOR($RIDEV_INPUTSINK, $RIDEV_NOLEGACY))
                DllStructSetData($tRID_HID, 'hwndTarget', $hGUI)
                $iNumDevices = 1
                _RegisterRawInputDevices($pRID_HID, $iNumDevices, $iRID_HID)
                $tRID_HID = 0
            EndIf
            $tRIDI_HID = 0
        EndIf
    Next
    
    $tRIDL = 0
EndIf

While 1
    Sleep(20)
WEnd


Func OnInput($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tRI_HID, $pRI_HID, $iRI_HID
   
    $tRI_KD = DllStructCreate($tagRAWINPUT_HID)
    $pRI_KD = DllStructGetPtr($tRI_HID)
    $iRI_KB = DllStructGetSize($tRI_HID)

    _GetRawInputData($ilParam, $RID_INPUT, $pRI_HID, $iRI_HID, $iRIH)
    If Not @error Then
        ConsoleWrite(DllStructGetData($tRI_HID, 'hDevice') & @LF)
        ConsoleWrite(DllStructGetData($tRI_HID, 'dwType') & @LF)
    EndIf
   
    $tRI_HID = 0
    Return 'GUI_RUNDEFMSG'
EndFunc

Func _EXIT()
    GUIDelete()
    Exit
EndFunc
Edited by Authenticity
Posted

try to obtain some info about xbox 360 gamepad.

try all script and obtain these info from Microsoft device:

\??\HID#VID_045E&PID_0719&IG_00#7&1b8910d2&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}

-HID Info:
    Vendor ID: 1118
    Product ID: 1817
    Version number: 0
    Top-level collection Usage Page: 1
    Top-level collection Usage: 5
-======================================================

can't use some script (last for example) because no GUI or other thing happens...

are there any way to detect pressed button with your script?

thank you for reply,

m.

Posted

Hi, the GUI window is deliberately invisible because it's there just to catch $WM_INPUT events. Can you run the script from SciTE editor and post the console output when you preform some actions with your game pad?

Posted

Thank you for your attention,

try to run with pad and no console output. Going mad.

only difference i found is in ID string

\??\HID#VID_045E&PID_0719&IG_00#7&1b8910d2&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}

Try to read your script and understand where recognize HID and start 'monitor'.

Authenticity, i want to inform you about one thing. Maybe you know, but a lot of people try to

getting work xbox 360 chatpad.

So start to communicate with xbox joypad is a BIG step for an enourmous community out of there.

Thank you for any effort in this sense.

m.

Posted (edited)

Because I have no xbox360 pad or any HID device to test this code with I'm only guessing:

#include <RawInput.au3>
#include <WinAPI.au3>
HotKeySet('{ESC}', '_EXIT')

Global $tRID_HID, $pRID_HID, $iRID_HID
Global $tRIH, $iRIH
Global $iNumDevices
Global $hGUI

$hGUI = GUICreate('Test', 100, 100)
GUIRegisterMsg($WM_INPUT, 'OnInput')

$tRID_HID = DllStructCreate($tagRAWINPUTDEVICE)
$pRID_HID = DllStructGetPtr($tRID_HID)
$iRID_HID = DllStructGetSize($tRID_HID)

$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$iRIH = DllStructGetSize($tRIH)

$iNumDevices = 1

DllStructSetData($tRID_HID, 'usUsagePage', 0x01)
DllStructSetData($tRID_HID, 'usUsage', 0x05)
DllStructSetData($tRID_HID, 'dwFlags', $RIDEV_INPUTSINK)
DllStructSetData($tRID_HID, 'hwndTarget', $hGUI)

_RegisterRawInputDevices($pRID_HID, $iNumDevices, $iRID_HID)

While 1
    Sleep(20)
WEnd


Func OnInput($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tRI_HID, $pRI_HID, $iRI_HID
    Local $iErrorCode
   
   
    $tRI_HID = DllStructCreate($tagRAWINPUT_HID)
    $pRI_HID = DllStructGetPtr($tRI_HID)
    $iRI_HID = DllStructGetSize($tRI_HID)
    
    $iErrorCode = _GetRawInputData($ilParam, $RID_INPUT, $pRI_HID, $iRI_HID, $iRIH)
    If @error Or $iErrorCode = $__UINT_ERROR Then
        ConsoleWrite(_WinAPI_GetLastErrorMessage())
    Else
        ConsoleWrite(DllStructGetData($tRI_HID, 'hDevice') & @LF)
        ConsoleWrite(DllStructGetData($tRI_HID, 'dwCount') & @LF)
    EndIf
    
    $tRI_HID = 0
    Return 'GUI_RUNDEFMSG'
EndFunc

Func _EXIT()
    GUIDelete()
    Exit
EndFunc

I'll upload another tiny fix of the library in the first page. If you can download it, it'd help here to catch errors.

Edited by Authenticity
Posted

Nice. If the handler get called I guess that the bRawData member of the structure contain unique one byte data for each button on your pad. If it's correct, all you need to do is to map the byte codes and do whatever you want to do with them. Can you post the codes and what is the button that is posting this code?

Posted

Try this within the OnInput() handler:

; ...
ConsoleWrite(DllStructGetData($tRI_HID, 'hDevice') & @LF)
ConsoleWrite(DllStructGetData($tRI_HID, 'dwCount') & @LF)
ConsoleWrite(DllStructGetData($tRI_HID, 'bRawData') & @LF)
; ...

If the bRawData member will return always the same value or the program will crash :) I think the bRawData should be declared as an array bytes in the size of dwCount. First test it, and read the RawInput.au3 file, everything is taken from MSDN and in my opinion is nicely and conveniently organized.

Posted

Hello everyone,

I'm having a _little_ problem with my own setup. Each of my production machines have a (cheap chineese infrared LED) USB barcode scanner attached. These device (all the same) are depicted as simple HID devices in Windows, but I don't succeed in having the handler invoked. What I'm looking for is to differentiate input from keyboard and input from barcode reader and direct barcode data to an ad-hoc code, without any user manipulation.

If it's really too difficult to achieve, I can still make my barcode have such a special header (e.g. an unusual control char) that it will be almost impossible to confuse with "daily" keyboard activity. The particular barcode for which this is needed would be scanned unattended and can have more or less any proprietary suitable format. Nonetheless it would be so much simpler if I could detect barcode input from the first byte on.

@ Authenticity: it seems that even if you don't have an HID device handy, you still have accumulated significant understanding of the context involved. Kudos to you!

I also guess that bRawData should be a buffer with significatnt size. I made my version use "ubyte bRawData[256]" buffer. I guess its enough for a "keyboard" even if somehow ugly. But it actually serves no purpose since the handler isn't called back. Do you happen to have an idea why it is so?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)

Hi, thanks for the nice feedback. Can you test the second script here and post the results?

Geez, it's more verbose than I thought. Registry seems to have kept informations from some previous hardware. I currently use a G15 keyboard (Logitech) and a MX620 Logitech mouse (8-button + wheel).

How can I help selecting the right device and/or removing traces of old devices?

EDIT: by diff on the script runs before and after connecting the same reader on another machine, I found it was this device.

-HID Info:

Vendor ID: 1241

Product ID: 5120

Version number: 323

Top-level collection Usage Page: 12

Top-level collection Usage: 1

-======================================================

-Mouse Info:

ID: 256

Number of buttons: 5

Sample rate: 0

Horizontal wheel: Not present

-======================================================

-Keyboard Info:

Keyboard type: 1

Keyboard subtype: 0

Keyboard mode: 1

Number of function keys: 12

Number of LED indicators: 3

Total number of keys: 264

-======================================================

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

OK. Now, can you test again another script to see if the OnInput() handler gets called when you preform any operation with the device?

#include <RawInput.au3>
#include <WinAPI.au3>
HotKeySet('{ESC}', '_EXIT')

Global $tRID_HID, $pRID_HID, $iRID_HID
Global $tRIH, $iRIH
Global $iNumDevices
Global $hGUI

$hGUI = GUICreate('Test', 100, 100)
GUIRegisterMsg($WM_INPUT, 'OnInput')

$tRID_HID = DllStructCreate($tagRAWINPUTDEVICE)
$pRID_HID = DllStructGetPtr($tRID_HID)
$iRID_HID = DllStructGetSize($tRID_HID)

$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$iRIH = DllStructGetSize($tRIH)

$iNumDevices = 1

DllStructSetData($tRID_HID, 'usUsagePage', 0x0C)
DllStructSetData($tRID_HID, 'usUsage', 0x01)
DllStructSetData($tRID_HID, 'dwFlags', $RIDEV_INPUTSINK)
DllStructSetData($tRID_HID, 'hwndTarget', $hGUI)

_RegisterRawInputDevices($pRID_HID, $iNumDevices, $iRID_HID)

While 1
    Sleep(20)
WEnd


Func OnInput($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tRI_HID, $pRI_HID, $iRI_HID
    Local $iErrorCode
   
   
    $tRI_HID = DllStructCreate($tagRAWINPUT_HID)
    $pRI_HID = DllStructGetPtr($tRI_HID)
    $iRI_HID = DllStructGetSize($tRI_HID)
   
    $iErrorCode = _GetRawInputData($ilParam, $RID_INPUT, $pRI_HID, $iRI_HID, $iRIH)
    If @error Or $iErrorCode = $__UINT_ERROR Then
        ConsoleWrite(_WinAPI_GetLastErrorMessage())
    Else
        ConsoleWrite(DllStructGetData($tRI_HID, 'hDevice') & @LF)
        ConsoleWrite(DllStructGetData($tRI_HID, 'dwCount') & @LF)
    EndIf
   
    $tRI_HID = 0
    Return 'GUI_RUNDEFMSG'
EndFunc

Func _EXIT()
    GUIDelete()
    Exit
EndFunc

If it gets called then I guess you'll know what to do next. Good-luck.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...