low-level keyboard using DirectInput

Discussion in 'C and C++' started by trismund, Jul 22, 2015.

  1. Code:
    #include <windows.h>
    #include <stdio.h>
    #include <InitGuid.h>
    #define DIRECTINPUT_VERSION 0x0800
    #include <dinput.h>
    #pragma comment (lib, "dinput8.lib")
    LPDIRECTINPUT8 din;   
    LPDIRECTINPUTDEVICE8 directinputdevice;  
    void InitializeDirectInput(HINSTANCE hInstance, HWND hWnd)
    void DetectKeys(void)
        static BYTE keystate[256];    
        directinputdevice->GetDeviceState(256, (LPVOID)keystate);
        if(keystate[DIK_A] & 0x80)  // Check for a depressed 'A'   
            printf("A\n");          // This is where you'll implement
                                    // your custom key capture routine  
    void CloseDirectInput(void)
    void MessageLoop()
        MSG msg;
            DWORD dwStartPoint = GetTickCount();
            if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
                if (msg.message == WM_QUIT)
            while ((GetTickCount() - dwStartPoint) < 25);
    DWORD WINAPI MyDirectInput(LPVOID lpParm)
        HINSTANCE hInstance = GetModuleHandle(NULL);
        InitializeDirectInput(hInstance, NULL);
        return 0;
    int main(int argc, char** argv)
        HANDLE hThread;
        DWORD dwThread;
        hThread = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)
            MyDirectInput, (LPVOID) argv[0], NULL, &dwThread);
        if (hThread)
            return WaitForSingleObject(hThread,INFINITE);
        else return 1;

  2. [mod]:good:Approved![/mod]

    pero kng ilang Features lng pedeng Auto On nlng hahahaha!~
  3. Ugh...

    C++ pla d maconvert :/
    hehehe pwede pa hingi ng vb.net or C# code :)
  4. Code:
    Imports Microsoft.DirectX Imports Microsoft.DirectX.DirectInput.CooperativeLevelFlags Imports Microsoft.DirectX.DirectInput
    Public Class Form1
        Inherits System.Windows.Forms.Form
       Dim KB As New DirectInput.Device(DirectInput.SystemGuid.Keyboard)
       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
           KB.SetCooperativeLevel(Me, Background Or NonExclusive)
       End Sub
       Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
           KB = Nothing
       End Sub
       Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
           Dim State As DirectInput.KeyboardState
           State = KB.GetCurrentKeyboardState
           If State.Item(Key.Escape) Then Me.Close()
           If State.Item(Key.A) Then Label1.Text &= "a"
           If State.Item(Key.B) Then Label1.Text &= "b"
           If State.Item(Key.C) Then Label1.Text &= "c"
       End Sub
    End Class
  5. Pwede yan kahit ilang features, depende sa code mo.
  6. Na try ko na to eh...
    kso hindi lumalabas ung Form1 ko na parang background lang sya or invisible :tehe:
    Visual Studio 2015 kasi gamit ko and DirectX 11 SDK.. dito kaya un? ang code na yan hindi gumagana dahil old version na yan :/
  7. Alam ko na itatanong ko....

    About *
    -Keyboard Hooking in VB.Net and
    -Sending Key in DirectX Game

    (I search for this that's why i get info about DirectInput)
  8. getasynckeystate na try mo na?
  9. Hindi pa, try ko plang.. :cool:
  10. Sir trismund :confused:

    pwede ba download kayo nito : http://www.ran-world.com/
    tapos kayo mag directinput :)

    hirap ksi eh.. getasynckeystate hindi working..
    sabi ng iba directinput daw.. bka daw dapat kpag directinput kung directx 9.0c daw sa game dapat yan din gamitin ko sa vb.net :)
  11. Sir Trismund!

    Ito nlang po request ko..

    AutoIt kasi pwede gamitin sa paggawa ng Auto Keyboard in DirectX Game..
    so... pwede po malaman or paturo tungkol dito..:

    Balak ko po kasi i attach ung AutoIt.exe file na sinasabi kong bot sa VB.net ko na ginagawa ko palang..
    at balak ko din po ksing gawing Invisible ung AutoIt.exe file na yan or gawing 0 Opacity.. kung alam nyo po pwede pa reply at kung hindi ignore nlng po :)
  12. [​IMG]
    Ito sir...

    Cannot find or open PDB files

    then after i launch the app manually in
    I get "WindowsApplication22.exe has stopped working."

    Any ideas?

    sir ung Low-level keyboard hook ba kpag ginamit ko pwede ko na gamitin ung Sendkey or Getasynckeystate?
    #13 WarOfRen, Aug 8, 2015
    Last edited by a moderator: Aug 8, 2015
  13. Susubukan ko pag may time. hindi na kasi ako masyado gumagamit ng Visual Basic
  14. Detected ba to ng xigncode3 ? ginamit ko ung proxycall ni silverdeath gumana .

Share This Page