IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

RAWINPUT BCB6 Window7


Sujet :

C++Builder

  1. #1
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut RAWINPUT BCB6 Window7
    Bonjours
    A la suite de deux poste sur le sujet, j'ai teste une souris HID, evidemment rien n'a fonctionne WM_INPUT n'etait jamais detecte, BuilderXE a peut etre des fonctions mieux integrees, apres recherches voici ce que j'ai trouve.

    le .cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    #include "stdio.h"
    #include "math.h"
    #include "rawinput.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    RAWINPUTDEVICE Rid[1];
    HRESULT hResult;
    HWND pProc;
    POINT cursor;
    static float X = 0;
    static float Y = 0;
    static float CursorX, CursorY;
    static float K = 0;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    // if(NULL == hwnd) return false;
    HMODULE hDll = LoadLibraryA("User32.dll");
    if(NULL == hDll)
            {
                    return;
            }
    pProc = GetProcAddress(hDll, "RegisterRawInputDevices");
    FreeLibrary(hDll);
    PRegisterRawInputDevices RegisterRawInputDevices = (PRegisterRawInputDevices)pProc;
     if(NULL == RegisterRawInputDevices) return;
     
     Rid[0].usUsagePage = 0x01;
     Rid[0].usUsage = 0x02;   // 0x02 Mouse ou 0x06  /  0x04 joystick  / 0x05 game pad
    // RIDEV_NOLEGACY pas d'arret du programme
    // RIDEV_INPUTSINK arret du programme pas de desactivation par un clic hors Form1
    // 0 arret du programme desactivation par un clic hors Form1 activer clic dans Form
     Rid[0].dwFlags = 0;
     Rid[0].hwndTarget = Form1->Handle;
    bool hResult = RegisterRawInputDevices(Rid, 1, sizeof(RAWINPUTDEVICE));
     if(hResult==0)
      ShowMessage("Erreur N°"+GetLastError());
    hDll = LoadLibraryA("User32.dll");
    if(NULL == hDll)
            {
                    return;
            }
    pProc = GetProcAddress(hDll, "GetRawInputData");
    FreeLibrary(hDll);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::WMInput(TMessage &Msg)
    {
    int i;
    Label1->Caption = i;
     UINT dwSize;
    PGetRawInputData GetRawInputData = (PGetRawInputData)pProc;
     GetRawInputData((HRAWINPUT)Msg.LParam, RID_INPUT, NULL, &dwSize,sizeof(RAWINPUTHEADER));
     LPBYTE lpb = new BYTE[dwSize];
     
     if (GetRawInputData((HRAWINPUT)Msg.LParam, RID_INPUT, lpb, &dwSize,
       sizeof(RAWINPUTHEADER)) != dwSize ) {}
     RAWINPUT* raw = (RAWINPUT*)lpb;
     if (raw->header.dwType == RIM_TYPEMOUSE)
     {
    Label2->Caption = raw->data.mouse.usFlags;
    Label3->Caption = raw->data.mouse.ulButtons;
    Label4->Caption = raw->data.mouse.usButtonFlags;
    Label5->Caption = raw->data.mouse.usButtonData;
    Label6->Caption = raw->data.mouse.ulRawButtons;
    Label7->Caption = raw->data.mouse.lLastX;
    Label8->Caption = raw->data.mouse.lLastY;
    Label9->Caption = raw->data.mouse.ulExtraInformation;
      if((int)raw->header.hDevice>65607)
      {
       SetCursorPos(CursorX, CursorY);
       X+= ((raw->data.mouse.lLastX)*2.54)/1000;
       Y+= ((raw->data.mouse.lLastY)*2.54)/1000;
       K=sqrt((X*X)+(Y*Y));
       if(X+Y<0)
        K = -K;
      }
      else
      {
       GetCursorPos(&cursor);
                            CursorX = cursor.x;
       CursorY = cursor.y;
      }
      Form1->Edit1->Text=CursorX;
      Form1->Edit2->Text=CursorY;
     }
     delete[] lpb;
     i = i++;
    }
    //---------------------------------------------------------------------------
    le .h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
     
    //---------------------------------------------------------------------------
    #ifndef Unit1H
    #define Unit1H
    #define WM_INPUT 0x00ff
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published: // IDE-managed Components
            TButton *Button1;
            TButton *Button2;
            TEdit *Edit1;
            TEdit *Edit2;
            TLabel *Label1;
            TLabel *Label2;
            TLabel *Label3;
            TLabel *Label4;
            TLabel *Label5;
            TLabel *Label6;
            TLabel *Label7;
            TLabel *Label8;
            TLabel *Label9;
            TLabel *Label10;
            TLabel *Label11;
            TLabel *Label12;
            TLabel *Label13;
            void __fastcall Button1Click(TObject *Sender);
    private: // User declarations
    public:  // User declarations
            __fastcall TForm1(TComponent* Owner);
     void __fastcall WMInput(TMessage &Msg);
     BEGIN_MESSAGE_MAP
      MESSAGE_HANDLER(WM_INPUT, TMessage, WMInput)
     END_MESSAGE_MAP(TForm)
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
    Il y a aussi un rawinput.h a ajouter
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
     
    #ifndef _RAWINPUT_H
    #define _RAWINPUT_H
    #include <windows.h>
     
    #define RIM_INPUT       0
    #define RIM_INPUTSINK   1
    typedef struct tagRAWINPUTHEADER {
        DWORD dwType;
        DWORD dwSize;
        HANDLE hDevice;
        WPARAM wParam;
    } RAWINPUTHEADER, *PRAWINPUTHEADER, *LPRAWINPUTHEADER;
     
    #define RIM_TYPEMOUSE       0
    #define RIM_TYPEKEYBOARD    1
    #define RIM_TYPEHID         2
    typedef struct tagRAWMOUSE {
        USHORT usFlags;
        union {
            ULONG ulButtons;
            struct  {
                USHORT  usButtonFlags;
                USHORT  usButtonData;
            };
        };
     
        ULONG ulRawButtons;
     
        LONG lLastX;
     
        LONG lLastY;
        ULONG ulExtraInformation;
    } RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;
     
    #define RI_MOUSE_LEFT_BUTTON_DOWN   0x0001  // Left Button changed to down.
    #define RI_MOUSE_LEFT_BUTTON_UP     0x0002  // Left Button changed to up.
    #define RI_MOUSE_RIGHT_BUTTON_DOWN  0x0004  // Right Button changed to down.
    #define RI_MOUSE_RIGHT_BUTTON_UP    0x0008  // Right Button changed to up.
    #define RI_MOUSE_MIDDLE_BUTTON_DOWN 0x0010  // Middle Button changed to down.
    #define RI_MOUSE_MIDDLE_BUTTON_UP   0x0020  // Middle Button changed to up.
    #define RI_MOUSE_BUTTON_1_DOWN      RI_MOUSE_LEFT_BUTTON_DOWN
    #define RI_MOUSE_BUTTON_1_UP        RI_MOUSE_LEFT_BUTTON_UP
    #define RI_MOUSE_BUTTON_2_DOWN      RI_MOUSE_RIGHT_BUTTON_DOWN
    #define RI_MOUSE_BUTTON_2_UP        RI_MOUSE_RIGHT_BUTTON_UP
    #define RI_MOUSE_BUTTON_3_DOWN      RI_MOUSE_MIDDLE_BUTTON_DOWN
    #define RI_MOUSE_BUTTON_3_UP        RI_MOUSE_MIDDLE_BUTTON_UP
    #define RI_MOUSE_BUTTON_4_DOWN      0x0040
    #define RI_MOUSE_BUTTON_4_UP        0x0080
    #define RI_MOUSE_BUTTON_5_DOWN      0x0100
    #define RI_MOUSE_BUTTON_5_UP        0x0200
    #define RI_MOUSE_WHEEL              0x0400
    #define MOUSE_MOVE_RELATIVE         0
    #define MOUSE_MOVE_ABSOLUTE         1
    #define MOUSE_VIRTUAL_DESKTOP    0x02  // the coordinates are mapped to the virtual desktop
    #define MOUSE_ATTRIBUTES_CHANGED 0x04  // requery for mouse attributes
    typedef struct tagRAWKEYBOARD {
        USHORT MakeCode;
        USHORT Flags;
        USHORT Reserved;
        USHORT VKey;
        UINT   Message;
        ULONG ExtraInformation;
     
    } RAWKEYBOARD, *PRAWKEYBOARD, *LPRAWKEYBOARD;
     
    #define KEYBOARD_OVERRUN_MAKE_CODE    0xFF
    #define RI_KEY_MAKE             0
    #define RI_KEY_BREAK            1
    #define RI_KEY_E0               2
    #define RI_KEY_E1               4
    #define RI_KEY_TERMSRV_SET_LED  8
    #define RI_KEY_TERMSRV_SHADOW   0x10
    typedef struct tagRAWHID {
        DWORD dwSizeHid;    // byte size of each report
        DWORD dwCount;      // number of input packed
        BYTE bRawData[1];
    } RAWHID, *PRAWHID, *LPRAWHID;
    typedef struct tagRAWINPUT {
        RAWINPUTHEADER header;
        union {
            RAWMOUSE    mouse;
            RAWKEYBOARD keyboard;
            RAWHID      hid;
        } data;
    } RAWINPUT, *PRAWINPUT, *LPRAWINPUT;
    #define RID_INPUT               0x10000003
    #define RID_HEADER              0x10000005
    typedef struct HRAWINPUT__ * HRAWINPUT;
    typedef
    UINT
    (_stdcall * PGetRawInputData)(
        HRAWINPUT hRawInput,
        UINT uiCommand,
        LPVOID pData,
        PUINT pcbSize,
        UINT cbSizeHeader
    );
     
    #define RIDI_PREPARSEDDATA      0x20000005
    #define RIDI_DEVICENAME         0x20000007  // the return valus is the character length, not the byte size
    #define RIDI_DEVICEINFO         0x2000000b
    typedef struct tagRID_DEVICE_INFO_MOUSE {
        DWORD dwId;
        DWORD dwNumberOfButtons;
        DWORD dwSampleRate;
    } 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
    (_stdcall * PGetRawInputDeviceInfoA)(
        HANDLE hDevice,
        UINT uiCommand,
        LPVOID pData,
        PUINT pcbSize
    );
    typedef
    UINT
    (_stdcall * PGetRawInputDeviceInfoW)(
        HANDLE hDevice,
        UINT uiCommand,
        LPVOID pData,
        PUINT pcbSize
    );
     
    typedef
    UINT
    (_stdcall * PGetRawInputBuffer)(
        PRAWINPUT pData,
        PUINT pcbSize,
        UINT cbSizeHeader
    );
    /*
     * Raw Input request APIs
     */
    typedef struct tagRAWINPUTDEVICE {
        USHORT usUsagePage; // Toplevel collection UsagePage
        USHORT usUsage;     // Toplevel collection Usage
        DWORD dwFlags;
        HWND hwndTarget;    // Target hwnd. NULL = follows keyboard focus
    } RAWINPUTDEVICE, *PRAWINPUTDEVICE, *LPRAWINPUTDEVICE;
    typedef CONST RAWINPUTDEVICE* PCRAWINPUTDEVICE;
    #define RIDEV_REMOVE            0x00000001
    #define RIDEV_EXCLUDE           0x00000010
    #define RIDEV_PAGEONLY          0x00000020
    #define RIDEV_NOLEGACY          0x00000030
    #define RIDEV_INPUTSINK         0x00000100
    #define RIDEV_CAPTUREMOUSE      0x00000200  // effective when mouse nolegacy is specified, otherwise it would be an error
    #define RIDEV_NOHOTKEYS         0x00000200  // effective for keyboard.
    #define RIDEV_APPKEYS           0x00000400  // effective for keyboard.
    #define RIDEV_EXMODEMASK        0x000000F0
    #define RIDEV_EXMODE(mode)  ((mode) & RIDEV_EXMODEMASK)
    typedef
    BOOL
    (_stdcall * PRegisterRawInputDevices)(
        PCRAWINPUTDEVICE pRawInputDevices,
        UINT uiNumDevices,
        UINT cbSize
    );
    typedef
    UINT
    (_stdcall * PGetRegisteredRawInputDevices)(
        PRAWINPUTDEVICE pRawInputDevices,
        PUINT puiNumDevices,
        UINT cbSize
    );
     
    typedef struct tagRAWINPUTDEVICELIST {
        HANDLE hDevice;
        DWORD dwType;
    } RAWINPUTDEVICELIST, *PRAWINPUTDEVICELIST;
    typedef
    UINT
    (_stdcall * PGetRawInputDeviceList)(
        PRAWINPUTDEVICELIST pRawInputDeviceList,
        PUINT puiNumDevices,
        UINT cbSize);
    typedef
    LRESULT
    (_stdcall * PDefRawInputProc)(
        PRAWINPUT *paRawInput,
        INT nInput,
        UINT cbSizeHeader
    );
    #define WM_INPUT 0x00ff
    #endif
    #ifndef _VKEY_H
    #define _VKEY_H
    struct VKeyInfo{
     USHORT VKey;
     LPCSTR VKname;
    };
    #define AddVKey(VK, VKName)   {(VK), (VKName)}
    static VKeyInfo vkis[] = {
      //AddVKey(VK_LBUTTON, "Left mouse button"),
      //AddVKey(VK_RBUTTON, "Right mouse button"),
            //AddVKey(VK_CANCEL, "Control-break processing"),
      //AddVKey(0x04, "[Middle mouse button (three-button mouse]"),
      //AddVKey(0x05, "X1 mouse button"),
      //AddVKey(0x06, "X2 mouse button"),
      AddVKey(0x07, "Undefined 0x07"),
      AddVKey(VK_BACK, "[BACKSPACE]"),
      AddVKey(VK_TAB, "[TAB]"),
      AddVKey(0x0A, "Reserved 0x0A"),
      AddVKey(0x0B, "Reserved 0x0B"),
      AddVKey(VK_CLEAR, "[CLEAR]"),
      AddVKey(VK_RETURN, "[ENTER]"),
      AddVKey(0x0E, "Undefined 0x0E"),
      AddVKey(0x0F, "Undefined 0x0F"),
      AddVKey(VK_SHIFT, "[SHIFT]"),
      AddVKey(VK_CONTROL, "[CTRL]"),
      AddVKey(VK_MENU, "[ALT]"),
      AddVKey(VK_PAUSE, "[PAUSE]"),
      AddVKey(VK_CAPITAL, "[caps lock]"),
      AddVKey(VK_KANA, "Input Method Editor (IME) Kana mode"),
      AddVKey(VK_HANGUL, "IME Hangul mode"),
      AddVKey(0x16, "Undefined 0x16"),
      AddVKey(VK_JUNJA, "IME Junja mode"),
      AddVKey(VK_FINAL, "IME final mode"),
      AddVKey(VK_HANJA, "IME Hanja mode"),
      AddVKey(VK_KANJI, "IME Kanji mode"),
      AddVKey(0x1A, "Undefined 0x1A"),
      AddVKey(VK_ESCAPE, "[ESC]"),
      AddVKey(VK_CONVERT, "IME convert"),
      AddVKey(VK_NONCONVERT, "IME nonconvert"),
      AddVKey(VK_ACCEPT, "IME accept"),
      AddVKey(VK_MODECHANGE, "IME mode change request"),
      AddVKey(VK_SPACE, "[space]"),
      AddVKey(VK_PRIOR, "[PAGE UP]"),
      AddVKey(VK_NEXT, "[PAGE DOWN]"),
      AddVKey(VK_END, "[END]"),
      AddVKey(VK_HOME, "[HOME]"),
      AddVKey(VK_LEFT, "[LEFT ARROW]"),
      AddVKey(VK_UP, "[UP ARROW]"),
      AddVKey(VK_RIGHT, "[RIGHT ARROW]"),
      AddVKey(VK_DOWN, "[DOWN ARROW]"),
      AddVKey(VK_SELECT, "[SELECT]"),
      AddVKey(VK_PRINT, "[PRINT]"),
      AddVKey(VK_EXECUTE, "[EXECUTE]"),
      AddVKey(VK_SNAPSHOT, "[PRINT SCREEN]"),
      AddVKey(VK_INSERT, "[INSERT]"),
      AddVKey(VK_DELETE, "[DEL]"),
      AddVKey(VK_HELP, "[HELP]"),
      AddVKey(0x30, "0"),
      AddVKey(0x31, "1"),
      AddVKey(0x32, "2"),
      AddVKey(0x33, "3"),
      AddVKey(0x34, "4"),
      AddVKey(0x35, "5"),
      AddVKey(0x36, "6"),
      AddVKey(0x37, "7"),
      AddVKey(0x38, "8"),
      AddVKey(0x39, "9"),
      AddVKey(0x3A, "Undefined 0x3A"),
      AddVKey(0x3B, "Undefined 0x3B"),
      AddVKey(0x3C, "Undefined 0x3C"),
      AddVKey(0x3D, "Undefined 0x3D"),
      AddVKey(0x3E, "Undefined 0x3E"),
      AddVKey(0x3F, "Undefined 0x3F"),
      AddVKey(0x40, "Undefined 0x3G"),
      AddVKey(0x41, "a"),
      AddVKey(0x42, "b"),
      AddVKey(0x43, "c"),
      AddVKey(0x44, "d"),
      AddVKey(0x45, "e"),
      AddVKey(0x46, "f"),
      AddVKey(0x47, "g"),
      AddVKey(0x48, "h"),
      AddVKey(0x49, "i"),
      AddVKey(0x4A, "j"),
      AddVKey(0x4B, "k"),
      AddVKey(0x4C, "l"),
      AddVKey(0x4D, "m"),
      AddVKey(0x4E, "n"),
      AddVKey(0x4F, "o"),
      AddVKey(0x50, "p"),
      AddVKey(0x51, "q"),
      AddVKey(0x52, "r"),
      AddVKey(0x53, "s"),
      AddVKey(0x54, "t"),
      AddVKey(0x55, "u"),
      AddVKey(0x56, "v"),
      AddVKey(0x57, "w"),
      AddVKey(0x58, "x"),
      AddVKey(0x59, "y"),
      AddVKey(0x5A, "z"),
      AddVKey(VK_LWIN, "Left Windows key (Microsoft Natural keyboard)"),
      AddVKey(VK_RWIN, "Right Windows key (Natural keyboard)"),
      AddVKey(VK_APPS, "Applications key (Natural keyboard)"),
      AddVKey(0x5E, "Reserved 0x5E"),
      AddVKey(VK_SLEEP, "Computer Sleep key"),
      AddVKey(VK_NUMPAD0, "Numeric keypad 0 key"),
      AddVKey(VK_NUMPAD1, "Numeric keypad 1 key"),
      AddVKey(VK_NUMPAD2, "Numeric keypad 2 key"),
      AddVKey(VK_NUMPAD3, "Numeric keypad 3 key"),
      AddVKey(VK_NUMPAD4, "Numeric keypad 4 key"),
      AddVKey(VK_NUMPAD5, "Numeric keypad 5 key"),
      AddVKey(VK_NUMPAD6, "Numeric keypad 6 key"),
      AddVKey(VK_NUMPAD7, "Numeric keypad 7 key"),
      AddVKey(VK_NUMPAD8, "Numeric keypad 8 key"),
      AddVKey(VK_NUMPAD9, "Numeric keypad 9 key"),
      AddVKey(VK_MULTIPLY, "Multiply key"),
      AddVKey(VK_ADD, "Add key"),
      AddVKey(VK_SEPARATOR, "Separator key"),
      AddVKey(VK_SUBTRACT, "Subtract key"),
      AddVKey(VK_DECIMAL, "Decimal key"),
      AddVKey(VK_DIVIDE, "Divide key"),
      AddVKey(VK_F1, "[F1]"),
      AddVKey(VK_F2, "[F2]"),
      AddVKey(VK_F3, "[F3]"),
      AddVKey(VK_F4, "[F4]"),
      AddVKey(VK_F5, "[F5]"),
      AddVKey(VK_F6, "[F6]"),
      AddVKey(VK_F7, "[F7]"),
      AddVKey(VK_F8, "[F8]"),
      AddVKey(VK_F9, "[F9]"),
      AddVKey(VK_F10, "[F10]"),
      AddVKey(VK_F11, "[F11]"),
      AddVKey(VK_F12, "[F12]"),
      AddVKey(VK_F13, "[F13]"),
      AddVKey(VK_F14, "[F14]"),
      AddVKey(VK_F15, "[F15]"),
      AddVKey(VK_F16, "[F16]"),
      AddVKey(VK_F17, "[F17]"),
      AddVKey(VK_F18, "[F18]"),
      AddVKey(VK_F19, "[F19]"),
      AddVKey(VK_F20, "[F20]"),
      AddVKey(VK_F21, "[F21]"),
      AddVKey(VK_F22, "[F22]"),
      AddVKey(VK_F23, "[F23]"),
      AddVKey(VK_F24, "[F24]"),
      AddVKey(0x88, "Unassigned 0x88"),
      AddVKey(0x89, "Unassigned 0x89"),
      AddVKey(0x8A, "Unassigned 0x8A"),
      AddVKey(0x8B, "Unassigned 0x8B"),
      AddVKey(0x8C, "Unassigned 0x8C"),
      AddVKey(0x8D, "Unassigned 0x8D"),
      AddVKey(0x8E, "Unassigned 0x8E"),
      AddVKey(0x8F, "Unassigned 0x8F"),
      AddVKey(VK_NUMLOCK, "[NUM LOCK]"),
      AddVKey(VK_SCROLL, "[SCROLL LOCK]"),
      AddVKey(0x92, "OEM specific 0x92"),
      AddVKey(0x93, "OEM specific 0x93"),
      AddVKey(0x94, "OEM specific 0x94"),
      AddVKey(0x95, "OEM specific 0x95"),
      AddVKey(0x96, "OEM specific 0x96"),
      AddVKey(0x97, "Unassigned 0x97"),
      AddVKey(0x98, "Unassigned 0x98"),
      AddVKey(0x99, "Unassigned 0x99"),
      AddVKey(0x9A, "Unassigned 0x9A"),
      AddVKey(0x9B, "Unassigned 0x9B"),
      AddVKey(0x9C, "Unassigned 0x9C"),
      AddVKey(0x9D, "Unassigned 0x9D"),
      AddVKey(0x9E, "Unassigned 0x9E"),
      AddVKey(0x9F, "Unassigned 0x9F"),
      AddVKey(VK_LSHIFT, "[Left SHIFT ]"),
      AddVKey(VK_RSHIFT, "[Right SHIFT]"),
      AddVKey(VK_LCONTROL, "[Left CONTROL]"),
      AddVKey(VK_RCONTROL, "[Right CONTROL]"),
      AddVKey(VK_LMENU, "Left MENU key"),
      AddVKey(VK_RMENU, "Right MENU key"),
      AddVKey(0xA6, "Back Key"),
      AddVKey(0xA7, "Forward Key"),
      AddVKey(0xA8, "Refresh Key"),
      AddVKey(0xA9, "Stop key"),
      AddVKey(0xAA, "Search key"),
      AddVKey(0xAB, "Favorites key"),
      AddVKey(0xAC, "Start and Home key"),
      AddVKey(0xAD, "Volume Mute key"),
      AddVKey(0xAE, "Volume Down key"),
      AddVKey(0xAF, "Volume Up key"),
      AddVKey(0xB0, "Next Track key"),
      AddVKey(0xB1, "Previous Track key"),
      AddVKey(0xB2, "Stop Media key"),
      AddVKey(0xB3, "Play/Pause Media key"),
      AddVKey(0xB4, "Start Mail key"),
      AddVKey(0xB5, "Select Media key"),
      AddVKey(0xB6, "Start Application 1 key"),
      AddVKey(0xB7, "Start Application 2 key"),
      AddVKey(0xB8, "Reserved 0xB8"),
      AddVKey(0xB9, "Reserved 0xB9"),
      AddVKey(VK_OEM_1, "miscellaneous charVK_OEM_1"),
      AddVKey(VK_OEM_PLUS, "For any country/region  VK_OEM_PLUS"),
      AddVKey(VK_OEM_COMMA, "For any country/region  VK_OEM_COMMA"),
      AddVKey(VK_OEM_MINUS, "For any country/region VK_OEM_MINUS"),
      AddVKey(VK_OEM_PERIOD, "For any country/region VK_OEM_PERIOD"),
      AddVKey(VK_OEM_2, " miscellaneous charVK_OEM_2"),
      AddVKey(VK_OEM_3, " miscellaneous charVK_OEM_3"),
      AddVKey(0xC1, "Reserved 0xC1"),
      AddVKey(0xC2, "Reserved 0xC2"),
      AddVKey(0xC3, "Reserved 0xC3"),
      AddVKey(0xC4, "Reserved 0xC4"),
      AddVKey(0xC5, "Reserved 0xC5"),
      AddVKey(0xC6, "Reserved 0xC6"),
      AddVKey(0xC7, "Reserved 0xC7"),
      AddVKey(0xC8, "Reserved 0xC8"),
      AddVKey(0xC9, "Reserved 0xC9"),
      AddVKey(0xCA, "Reserved 0xCA"),
      AddVKey(0xCB, "Reserved 0xCB"),
      AddVKey(0xCC, "Reserved 0xCC"),
      AddVKey(0xCD, "Reserved 0xCD"),
      AddVKey(0xCE, "Reserved 0xCE"),
      AddVKey(0xCF, "Reserved 0xCF"),
      AddVKey(0xD0, "Reserved 0xD0"),
      AddVKey(0xD1, "Reserved 0xD1"),
      AddVKey(0xD2, "Reserved 0xD2"),
      AddVKey(0xD3, "Reserved 0xD3"),
      AddVKey(0xD4, "Reserved 0xD4"),
      AddVKey(0xD5, "Reserved 0xD5"),
      AddVKey(0xD6, "Reserved 0xD6"),
      AddVKey(0xD7, "Reserved 0xD7"),
      AddVKey(0xD8, "Unassigned "),
      AddVKey(0xD9, "Unassigned 0xD9"),
      AddVKey(0xDA, "Unassigned 0xDA"),
      AddVKey(VK_OEM_4, "Used for miscellaneous char VK_OEM_4"),
         AddVKey(VK_OEM_5, "Used for miscellaneous char VK_OEM_5"),
      AddVKey(VK_OEM_6, "Used for miscellaneous char VK_OEM_6"),
         AddVKey(VK_OEM_7, " miscellaneous char VK_OEM_7"),
      AddVKey(VK_OEM_8, "miscellaneous char VK_OEM_8"),
      AddVKey(0xE0, "Reserved 0xE0"),
      AddVKey(0xE1, "OEM specific 0xE1"),
      AddVKey(VK_OEM_102, " Either the angle bracket key or the backslash key VK_OEM_102"),
      AddVKey(0xE3, "OEM specific 0xE3"),
      AddVKey(0xE4, "OEM specific 0xE4"),
      AddVKey(VK_PROCESSKEY, "PROCESS key"),
      AddVKey(0xE6, "OEM specific 0xE6"),
      AddVKey(0xE7, "Unicode char  VK_PACKET  32-bit Virtual Key 0xE7"),
      AddVKey(0xE8, "Unassigned 0xE8"),
      AddVKey(0xE9, "OEM specific 0xE9"),
      AddVKey(0xEA, "OEM specific 0xEA"),
      AddVKey(0xEB, "OEM specific 0xEB"),
      AddVKey(0xEC, "OEM specific 0xEC"),
      AddVKey(0xED, "OEM specific 0xED"),
      AddVKey(0xEF, "OEM specific 0xEF"),
      AddVKey(0xF0, "OEM specific 0xF0"),
      AddVKey(0xF1, "OEM specific 0xF1"),
      AddVKey(0xF2, "OEM specific 0xF2"),
      AddVKey(0xF3, "OEM specific 0xF3"),
      AddVKey(0xF4, "OEM specific 0xF4"),
      AddVKey(0xF5, "OEM specific 0xF5"),
      AddVKey(VK_ATTN, "Attn key"),
      AddVKey(VK_CRSEL, "CrSel key"),
      AddVKey(VK_EXSEL, "ExSel key"),
      AddVKey(VK_EREOF, "Erase EOF key"),
      AddVKey(VK_PLAY, "Play key"),
      AddVKey(VK_ZOOM, "Zoom key"),
         AddVKey(VK_NONAME, "Reserved"),
         AddVKey(VK_PA1, "PA1 key"),
      AddVKey(VK_OEM_CLEAR, "Clear key"),
      AddVKey(0xFF, "Virtual-Key Code 0xFF")
    };
     
    LPCSTR GetKeyName(USHORT VKey)
    {
    int i;
     for(i = 0; i < sizeof(vkis); i++)
     {
      if(VKey == vkis[i].VKey)
       return vkis[i].VKname;
     }
     return vkis[--i].VKname;
    }
     
    #endif
    Le code n'est pas parfait mais cela fonctionne, il me reste a trouver comment capturer un joystick ou un game pad, mais la je n'ai pas trouve d'exemples
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  2. #2
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Apres de nombreuses recherches voici comment recueillir les message d'un joystick USB HID, celui utilise pour mon teste possede 14 boutons, tous sont detectes
    le .cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    #include "stdio.h"
    #include "rawinput.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    RAWINPUTDEVICE Rid[1];
    HRESULT hResult;
    HWND pProc;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    // <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645546(v=vs.85).aspx" target="_blank">http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx</a>
    // <a href="http://www.asawicki.info/pub/WGK2011/gamepad_code/test.cpp" target="_blank">www.asawicki.info/pub/WGK2011/gamepad_code/test.cpp</a>
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    // if(NULL == hwnd) return false;
    HMODULE hDll = LoadLibraryA("User32.dll");
    if(NULL == hDll)
            {
                    return;
            }
    pProc = GetProcAddress(hDll, "RegisterRawInputDevices");
    FreeLibrary(hDll);
    PRegisterRawInputDevices RegisterRawInputDevices = (PRegisterRawInputDevices)pProc;
     if(NULL == RegisterRawInputDevices) return;
     
     Rid[0].usUsagePage = 0x01;
     Rid[0].usUsage = 0x04;   // 0x02 Mouse ou 0x06  /  0x04 joystick  / 0x05 game pad
    // RIDEV_NOLEGACY pas d'arret du programme
    // RIDEV_INPUTSINK arret du programme pas de desactivation par un clic hors Form1
    // 0 arret du programme desactivation par un clic hors Form1 activer clic dans Form
     Rid[0].dwFlags = 0;
     Rid[0].hwndTarget = Form1->Handle;
    bool hResult = RegisterRawInputDevices(Rid, 1, sizeof(RAWINPUTDEVICE));
     if(hResult==0)
      ShowMessage("Erreur N°"+GetLastError());
    hDll = LoadLibraryA("User32.dll");
    if(NULL == hDll)
            {
                    return;
            }
    pProc = GetProcAddress(hDll, "GetRawInputData");
    FreeLibrary(hDll);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::WMInput(TMessage &Msg)
    {
     UINT dwSize;
    PGetRawInputData GetRawInputData = (PGetRawInputData)pProc;
     GetRawInputData((HRAWINPUT)Msg.LParam, RID_INPUT, NULL, &dwSize,sizeof(RAWINPUTHEADER));
     LPBYTE lpb = new BYTE[dwSize];
     
     if (GetRawInputData((HRAWINPUT)Msg.LParam, RID_INPUT, lpb, &dwSize,
       sizeof(RAWINPUTHEADER)) != dwSize ) {}
     RAWINPUT* raw = (RAWINPUT*)lpb;
            if (raw->header.dwType == RIM_TYPEHID)
            {
    printf("Input from device %08X, SizeHid=%u, Count=%u\n",
       raw->header.hDevice, raw->data.hid.dwSizeHid, raw->data.hid.dwCount);
      const BYTE *ptr = raw->data.hid.bRawData;
      char buf1[256] = { 0 }, buf2[32];
      for (DWORD i = 0; i < raw->data.hid.dwCount; ++i)
      {
       for (DWORD byte = 0; byte < raw->data.hid.dwSizeHid; ++byte)
       {
        sprintf(buf2, " %02X", *ptr);
        strcat(buf1, buf2);
        ++ptr;
       }
       strcat(buf1, "\n");
      }
      printf(buf1);
    Edit1->Text = buf1;
    Edit2->Text = buf2;
            }
     
     delete[] lpb;
    }
    le .h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    //---------------------------------------------------------------------------
    #ifndef Unit1H
    #define Unit1H
    #define WM_INPUT 0x00ff
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published: // IDE-managed Components
            TButton *Button1;
            TEdit *Edit1;
            TEdit *Edit2;
            void __fastcall Button1Click(TObject *Sender);
    private: // User declarations
    public:  // User declarations
            __fastcall TForm1(TComponent* Owner);
     void __fastcall WMInput(TMessage &Msg);
     BEGIN_MESSAGE_MAP
      MESSAGE_HANDLER(WM_INPUT, TMessage, WMInput)
     END_MESSAGE_MAP(TForm)
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
    le fichier " rawinput.h " est le meme que celui du post precedent
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  3. #3
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Voici a titre indicatif les valeurs relevees dans les TEdits pour chaque boutton de la manette
    manette Logitech Precision

    manette au repos
    00 80 80 00 C0
    C0

    stick gauche
    boutton haut 00 80 01 00 D0
    D0
    boutton gauche 00 01 80 00 C4
    C4
    boutton bas 00 80 FF 00 E0
    E0
    boutton droit 00 FF 80 00 C8
    C8

    stick droit
    boutton haut 00 80 80 08 C0
    C0
    boutton gauche 00 80 80 01 C0
    C0
    boutton bas 00 80 80 02 C0
    C0
    boutton droit 00 80 80 04 C0
    C0

    bouttons central
    boutton gauche 00 80 80 00 C1
    C1
    boutton droit 00 80 80 00 C2
    C2

    bouttons droit
    boutton haut 00 80 80 10 C0
    C0
    boutton bas 00 80 80 40 C0
    C0

    bouttons gauche
    boutton haut 00 80 80 20 C0
    C0
    boutton bas 00 80 80 80 C0
    C0
    Il me reste a voir comment utiliser toutes ces valeurs
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  4. #4
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Je n'arrive pas a trouver comment tester ces valeurs afin d'assurer un traitement
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  5. #5
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    J'ai reussi a recuperer les valeurs renvoyees par la manette, voici le code
    le .cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    #include "stdio.h"
    #include "rawinput.h"
    #include "assert.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    RAWINPUTDEVICE Rid[1];
    HRESULT hResult;
    HWND pProc;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    // <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645546(v=vs.85).aspx" target="_blank">http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx</a>
    // <a href="http://www.asawicki.info/pub/WGK2011/gamepad_code/test.cpp" target="_blank">www.asawicki.info/pub/WGK2011/gamepad_code/test.cpp</a>
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    // if(NULL == hwnd) return false;
    HMODULE hDll = LoadLibraryA("User32.dll");
    if(NULL == hDll)
            {
                    return;
            }
    pProc = GetProcAddress(hDll, "RegisterRawInputDevices");
    FreeLibrary(hDll);
    PRegisterRawInputDevices RegisterRawInputDevices = (PRegisterRawInputDevices)pProc;
     if(NULL == RegisterRawInputDevices) return;
     
     Rid[0].usUsagePage = 0x01;
     Rid[0].usUsage = 0x04;   // 0x02 Mouse ou 0x06  /  0x04 joystick  / 0x05 game pad
    // RIDEV_NOLEGACY pas d'arret du programme
    // RIDEV_INPUTSINK arret du programme pas de desactivation par un clic hors Form1
    // 0 arret du programme desactivation par un clic hors Form1 activer clic dans Form
     Rid[0].dwFlags = 0;
     Rid[0].hwndTarget = Form1->Handle;
    bool hResult = RegisterRawInputDevices(Rid, 1, sizeof(RAWINPUTDEVICE));
     if(hResult==0)
      ShowMessage("Erreur N°"+GetLastError());
    hDll = LoadLibraryA("User32.dll");
    if(NULL == hDll)
            {
                    return;
            }
    pProc = GetProcAddress(hDll, "GetRawInputData");
    FreeLibrary(hDll);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::WMInput(TMessage &Msg)
    {
     UINT dwSize;
    PGetRawInputData GetRawInputData = (PGetRawInputData)pProc;
     GetRawInputData((HRAWINPUT)Msg.LParam, RID_INPUT, NULL, &dwSize,sizeof(RAWINPUTHEADER));
     LPBYTE lpb = new BYTE[dwSize];
     if (GetRawInputData((HRAWINPUT)Msg.LParam, RID_INPUT, lpb, &dwSize,
       sizeof(RAWINPUTHEADER)) != dwSize ) {}
     RAWINPUT* raw = (RAWINPUT*)lpb;
            if (raw->header.dwType == RIM_TYPEHID)
            {
    printf("Input from device %08X, SizeHid=%u, Count=%u\n",
       raw->header.hDevice, raw->data.hid.dwSizeHid, raw->data.hid.dwCount);
      const BYTE *ptr = raw->data.hid.bRawData;
      char buf1[16] = { 0 }, buf2[4];
      for (DWORD i = 0; i < raw->data.hid.dwCount; ++i)
      {
       for (DWORD byte = 0; byte < raw->data.hid.dwSizeHid; ++byte)
       {
    //float eee = ((int)raw->data.hid.bRawData[byte] - 0x80) * 0.0078125f;
               sprintf(buf2, " %02X", *ptr);
        strcat(buf1, buf2);
        ++ptr;
       }
       //strcat(buf1, "\n");
      }
      printf(buf1);
    // ici on verifie les valeurs retournees
    Label19->Caption = ((int)raw->data.hid.bRawData[1]);
    Label20->Caption = ((int)raw->data.hid.bRawData[2]);
    Label21->Caption = ((int)raw->data.hid.bRawData[3]);
    Label22->Caption = ((int)raw->data.hid.bRawData[4] & 0x0F);
    // Label19 renvoi la manette gauche sens horizontale 1, 255 ainsi que Label12
    // Label20 renvoi la manette gauche sens verticale 1, 255 ainsi que Label12
    // Label21 renvoi la manette droite 1, 2, 4, 8
    // Label21 renvoi les 4 bouttons droit et gauche 16, 32, 64, 128
    // Label22 renvoi les deux boutons centraux  81, 82 ou A1, A2 ou C1, C2 faire un & avec 0x0F pour recuperer uniquement le dernier chiffre
    // on affiche les valeurs
    Edit1->Text = buf1;
    Edit2->Text = buf2;
    // pour les testes on color un TLabel contenant uniquement 4 espaces et
    // qui sont positionnes de facon a representer la disposition de la manette
            switch(((int)raw->data.hid.bRawData[2]))
            {
            case 1:
            Label1->Color = clRed;
            break;
            case 255:
            Label3->Color = clRed;
            break;
            case 128:
            Label1->Color = clBtnFace;
            Label3->Color = clBtnFace;
            break;
            }
    //============
            switch(((int)raw->data.hid.bRawData[1]))
            {
            case 1:
            Label2->Color = clRed;
            break;
            case 255:
            Label4->Color = clRed;
            break;
            case 128:
            Label2->Color = clBtnFace;
            Label4->Color = clBtnFace;
            break;
            }
    //============
            switch(((int)raw->data.hid.bRawData[3]))
            {
            case 0:
            Label5->Color = clBtnFace;
            Label6->Color = clBtnFace;
            Label7->Color = clBtnFace;
            Label8->Color = clBtnFace;
            Label9->Color = clBtnFace;
            Label10->Color = clBtnFace;
            Label11->Color = clBtnFace;
            Label12->Color = clBtnFace;
            break;
            case 1:
            Label7->Color = clRed;
            break;
            case 2:
            Label6->Color = clRed;
            break;
            case 4:
            Label8->Color = clRed;
            break;
            case 8:
            Label5->Color = clRed;
            break;
            case 16:
            Label10->Color = clRed;
            break;
            case 32:
            Label12->Color = clRed;
            break;
            case 64:
            Label9->Color = clRed;
            break;
            case 128:
            Label11->Color = clRed;
            break;
            }
    //============
            switch(((int)raw->data.hid.bRawData[4] & 0x0F))
            {
            case 0:
            Label13->Color = clBtnFace;
            Label14->Color = clBtnFace;
            break;
            case 1:
            Label13->Color = clRed;
            break;
            case 2:
            Label14->Color = clRed;
            break;
            }
            }
     delete[] lpb;
    }
    //---------------------------------------------------------------------------
    le .h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
     
    //---------------------------------------------------------------------------
    #ifndef Unit1H
    #define Unit1H
    #define WM_INPUT 0x00ff
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published: // IDE-managed Components
            TButton *Button1;
            TEdit *Edit1;
            TEdit *Edit2;
            TLabel *Label19;
            TLabel *Label20;
            TLabel *Label21;
            TLabel *Label22;
            TLabel *Label1;
            TLabel *Label2;
            TLabel *Label3;
            TLabel *Label4;
            TLabel *Label5;
            TLabel *Label6;
            TLabel *Label7;
            TLabel *Label8;
            TLabel *Label9;
            TLabel *Label10;
            TLabel *Label11;
            TLabel *Label12;
            TLabel *Label13;
            TLabel *Label14;
            void __fastcall Button1Click(TObject *Sender);
    private: // User declarations
    public:  // User declarations
            __fastcall TForm1(TComponent* Owner);
     void __fastcall WMInput(TMessage &Msg);
     BEGIN_MESSAGE_MAP
      MESSAGE_HANDLER(WM_INPUT, TMessage, WMInput)
     END_MESSAGE_MAP(TForm)
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
    Avec RAWINPUT il suffit de brancher le periferique des qu'il est installe par windows, il est reconnu par le programme, pas besoin de driver HID a programmer
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  6. #6
    Membre du Club
    Inscrit en
    Avril 2008
    Messages
    76
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 76
    Points : 59
    Points
    59
    Par défaut
    Pour faire des recherches sur les fonctionnalités de XE c'est assez simple car la seule aide complete c'est leur wiki :

    http://docwiki.embarcadero.com/RADStudio/fr/

    Cela dit si tu veux que je recherche sur la version XE2 je serais ravis de t'aider.

  7. #7
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Je programme uniquement pour mon usage perso et j'hesite a investir pour un nouveau programme
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  8. #8
    Membre émérite
    Inscrit en
    Avril 2010
    Messages
    1 495
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1 495
    Points : 2 274
    Points
    2 274
    Par défaut
    Salut,

    Si tu es encore sous bcb6 ce serait peut-être intéressant pour toi de migrer. Je teste actuellement Code::Block et wxWidgets, prochainement Qt. J'ai lancé une discussion sur le sujet, le but est d'avoir un environnement de développement libre et moderne.

  9. #9
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    La version bcb6 fonctionne meme sous Window7, je vais la conserver encore un peux
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  10. #10
    Membre émérite
    Inscrit en
    Avril 2010
    Messages
    1 495
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1 495
    Points : 2 274
    Points
    2 274
    Par défaut
    Je me doute qu'il fonctionne. La question à se poser c'est plutôt, est-ce que bcb6 offre les avantages d'un compilateur et d'un "framework" (lib et ihm) plus récents ? Après bien sûr, le laisser sur ton disque dur à portée de main n'est pas incompatible avec l'essai d'un autre EDI, qui plus est, libre, du moins en ce qui concerne celui précédemment cité.

Discussions similaires

  1. BCB6 => Remplir un ListView
    Par totofweb dans le forum C++Builder
    Réponses: 6
    Dernier message: 25/02/2004, 15h12
  2. [BCB6] Probleme onglet dans IDE
    Par bgautier dans le forum C++Builder
    Réponses: 5
    Dernier message: 21/01/2004, 16h20
  3. [BCB6] DBGrid et mode de connexion BDD... demain
    Par Seb des Monts dans le forum C++Builder
    Réponses: 5
    Dernier message: 19/01/2004, 13h56
  4. Bug de SelectDirectory à la compilation (BCB6)
    Par benj63 dans le forum C++Builder
    Réponses: 4
    Dernier message: 16/01/2004, 07h49
  5. PB d'import avec les ActiveX sous BCB6
    Par dergen dans le forum C++Builder
    Réponses: 4
    Dernier message: 29/11/2002, 10h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo