UDF > WinAPIEx > System > User Raw Input >


_WinAPI_RegisterRawInputDevices

Enregistre les périphériques qui fournissent les données d'entrée de base

#include <WinAPISys.au3>
_WinAPI_RegisterRawInputDevices ( $paDevice [, $iCount = 1] )

Paramètres

$paDevice Un pointeur sur un tableau de structures $tagRAWINPUTDEVICE qui représente les périphériques qui alimentent l'entrée de base.
$iCount [optionnel] Le nombre d'entrées dans le tableau. Par défaut, 1.

Valeur de retour

Succès: Retourne True.
Échec: Retourne False, appelez _WinAPI_GetLastError() pour obtenir des informations sur l'erreur.

Remarques

Pour recevoir des messages WM_INPUT, une application doit d'abord enregistrer les périphériques d'entrée de base en utilisant _WinAPI_RegisterRawInputDevices().

Pour recevoir des messages WM_INPUT_DEVICE_CHANGE, une application doit préciser le flag $RIDEV_DEVNOTIFY pour chaque classe de périphérique spécifiée par les champs "UsagePage" et "Usage" de la structure $tagRAWINPUTDEVICE.

En relation

_WinAPI_GetRawInputData

Voir aussi

Consultez RegisterRawInputDevices dans la librairie MSDN.

Exemple

#include <APISysConstants.au3>
#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WinAPIConv.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WinAPIRes.au3>
#include <WinAPISys.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

Opt('TrayAutoPause', 0)

Global $g_ahPart[9]
; Charge les bitmaps (Mice*.bmp) qui sont nécessaires à l'affichage des images
For $i = 0 To 6
    $g_ahPart[$i] = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\Mice'& $i & '.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
Next

; Copie les bitmaps pour dessiner correctement "Mice"
$g_ahPart[7] = _WinAPI_CopyBitmap($g_ahPart[0])
$g_ahPart[8] = _WinAPI_CopyBitmap($g_ahPart[6])

; Crée une GUI
Global $g_hForm = GUICreate('Test '& StringReplace(@ScriptName, '.au3', '()'), 160, 212, @DesktopWidth - 179, @DesktopHeight - 283, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST)
Global $g_idPic = GUICtrlCreatePic('', 0, 0, 160, 160)
GUICtrlCreateGraphic(0, 160, 160, 1)
GUICtrlSetBkColor(-1, 0xDFDFDF)
GUICtrlCreateLabel('X:', 10, 170, 12, 14)
Global $g_aidLabel[3]
$g_aidLabel[0] = GUICtrlCreateLabel('', 23, 170, 30, 14)
GUICtrlCreateLabel('Y:', 10, 190, 12, 14)
$g_aidLabel[1] = GUICtrlCreateLabel('', 23, 190, 30, 14)
GUICtrlCreateLabel('Wheel:', 80, 170, 36, 14)
$g_aidLabel[2] = GUICtrlCreateLabel('', 117, 170, 30, 14)

_SetBitmap($g_idPic, $g_ahPart[0])

; Pour obtenir les valeurs des membres "UsagePage" et "Usage" de cette structure, lire la documentation HID Usage Tables
; http://www.usb.org/developers/devclass_docs/HID1_11.pdf
Global $tRID = DllStructCreate($tagRAWINPUTDEVICE)
DllStructSetData($tRID, 'UsagePage', 0x01) ; Contrôles de bureau génériques
DllStructSetData($tRID, 'Usage', 0x02) ; souris
DllStructSetData($tRID, 'Flags', $RIDEV_INPUTSINK)
DllStructSetData($tRID, 'hTarget', $g_hForm)
Local $pRID = DllStructGetPtr($tRID)

; Inscrire l'entrée HID pour obtenir l'entrée de la ligne à partir de Mice
_WinAPI_RegisterRawInputDevices($pRID)

; Inscrit le message WM_INPUT
GUIRegisterMsg($WM_INPUT, 'WM_INPUT')

GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SetBitmap($hWnd, $hBitmap, $bUpdate = 0)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
        If Not $hWnd Then
            Return 0
        EndIf
    EndIf

    $hBitmap = _WinAPI_CopyBitmap($hBitmap)
    If @error Then
        Return 0
    EndIf
    Local $hPrev = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    If $hPrev Then
        _WinAPI_DeleteObject($hPrev)
    EndIf
    $hPrev = _SendMessage($hWnd, $STM_GETIMAGE)
    If $hPrev <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf
    If $bUpdate Then
        _WinAPI_UpdateWindow($hWnd)
    EndIf
    Return 1
EndFunc   ;==>_SetBitmap

Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam

    Switch $hWnd
        Case $g_hForm
            Local $tRIM = DllStructCreate($tagRAWINPUTMOUSE)
            If _WinAPI_GetRawInputData($lParam, DllStructGetPtr($tRIM), DllStructGetSize($tRIM), $RID_INPUT) Then
                Local $iFlags = DllStructGetData($tRIM, 'Flags')
                Select
                    Case BitAND($iFlags, $MOUSE_ATTRIBUTES_CHANGED)
                        ; Vous devez interroger les attributs de la souris et mettre à jour le  bitmap...
                    Case Else

                EndSelect
                $iFlags = DllStructGetData($tRIM, 'ButtonFlags')
                If BitAND($iFlags, BitOR($RI_MOUSE_MIDDLE_BUTTON_DOWN, $RI_MOUSE_MIDDLE_BUTTON_UP, $RI_MOUSE_LEFT_BUTTON_DOWN, $RI_MOUSE_LEFT_BUTTON_UP, $RI_MOUSE_RIGHT_BUTTON_DOWN, $RI_MOUSE_RIGHT_BUTTON_UP)) Then
                    Local $hDC = _WinAPI_CreateCompatibleDC(0)
                    Local $hSv = _WinAPI_SelectObject($hDC, $g_ahPart[8])
                    Select
                        Case BitAND($iFlags, $RI_MOUSE_MIDDLE_BUTTON_DOWN)
                            _WinAPI_DrawBitmap($hDC, 0, 0, $g_ahPart[5])
                        Case BitAND($iFlags, $RI_MOUSE_MIDDLE_BUTTON_UP)
                            _WinAPI_DrawBitmap($hDC, 0, 0, $g_ahPart[6])
                    EndSelect
                    _WinAPI_SelectObject($hDC, $g_ahPart[7])
                    Select
                        Case BitAND($iFlags, $RI_MOUSE_LEFT_BUTTON_DOWN)
                            _WinAPI_DrawBitmap($hDC, 39, 25, $g_ahPart[1])
                        Case BitAND($iFlags, $RI_MOUSE_LEFT_BUTTON_UP)
                            _WinAPI_DrawBitmap($hDC, 39, 25, $g_ahPart[2])
                        Case BitAND($iFlags, $RI_MOUSE_RIGHT_BUTTON_DOWN)
                            _WinAPI_DrawBitmap($hDC, 81, 25, $g_ahPart[3])
                        Case BitAND($iFlags, $RI_MOUSE_RIGHT_BUTTON_UP)
                            _WinAPI_DrawBitmap($hDC, 81, 25, $g_ahPart[4])
                    EndSelect
                    _WinAPI_DrawBitmap($hDC, 74, 33, $g_ahPart[8])
                    _WinAPI_SelectObject($hDC, $hSv)
                    _WinAPI_DeleteDC($hDC)
                    _SetBitmap($g_idPic, $g_ahPart[7])
                EndIf
                Local $aData = MouseGetPos()
                For $i = 0 To 1
                    If StringCompare(GUICtrlRead($g_aidLabel[$i]), $aData[$i]) Then
                        GUICtrlSetData($g_aidLabel[$i], $aData[$i])
                    EndIf
                Next
                If BitAND($iFlags, $RI_MOUSE_WHEEL) Then
                    $aData = _WinAPI_WordToShort(DllStructGetData($tRIM, 'ButtonData'))
                    If $aData > 0 Then
                        $aData = 'Up'
                    Else
                        $aData = 'Down'
                    EndIf
                Else
                    $aData = ''
                EndIf
                If StringCompare(GUICtrlRead($g_aidLabel[2]), $aData) Then
                    GUICtrlSetData($g_aidLabel[2], $aData)
                EndIf
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_INPUT