1. Pinoy Hideout is the Ultimate Pinoy Chat, Mobile and PC Community
    We have been leading the scene for over 7 years and currently offer:
    • latest and updated game cheats and softwares
    • internet tricks for your android phone, mobile network, and computer
    • a staff team who helps protect its members from malware while enforcing a great community

    • You must register an account before you can post, download files, and see any advanced features or content.

Dismiss Notice
Announcement!
Gusto mo bang makakuha ng VIP subcription ng libre? CLICK HERE<

low-level keyboard using DirectInput

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

  1. trismund

    trismund King in the East
    Staff Member Administrator SF1 VIP

    Reputations:
    378
    Joined:
    Oct 28, 2012
    Posts:
    2,787
    Likes Received:
    444
    Trophy Points:
    0

    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)
    {
        DirectInput8Create(hInstance,   
            DIRECTINPUT_VERSION,    
            IID_IDirectInput8,    
            (void**)&din,    
            NULL);   
        din->CreateDevice(GUID_SysKeyboard,  
            &directinputdevice,   
            NULL);    
        directinputdevice->SetDataFormat(&c_dfDIKeyboard); 
        directinputdevice->SetCooperativeLevel(hWnd,
            DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
    }
    
    void DetectKeys(void)
    {
        static BYTE keystate[256];    
        directinputdevice->Acquire();   
        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)
    {
        directinputdevice->Unacquire(); 
        din->Release();    
    }
    
    void MessageLoop()
    {
        MSG msg;
        while(TRUE)
        {
            DWORD dwStartPoint = GetTickCount();
            if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
            {
                if (msg.message == WM_QUIT)
                    break;
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            } 
            DetectKeys();
            while ((GetTickCount() - dwStartPoint) < 25);
        }
        CloseDirectInput();
    }
    
    DWORD WINAPI MyDirectInput(LPVOID lpParm)
    {
        HINSTANCE hInstance = GetModuleHandle(NULL);
        InitializeDirectInput(hInstance, NULL);
        MessageLoop();
        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. Jhunz1337

    Jhunz1337 Coach
    Established Member

    Reputations:
    0
    Joined:
    Jul 4, 2014
    Posts:
    251
    Likes Received:
    2
    Trophy Points:
    0

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

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

    WarOfRen Leecher

    Reputations:
    0
    Joined:
    Aug 3, 2015
    Posts:
    8
    Likes Received:
    0
    Trophy Points:
    0

    Haaaiizzzz!!!!

    Ngaung araw halos 24 hours ako nag search for DirectInput in VB.Net pero hindi talaga gumana..
    naisip ko mag post ako ng request dito :)
    tapos bigla kong nakita to!!!!
    Convert konalang salamat sir Tristmund!

    gagamitin ko ksi sa RanWorld pra sa auto keyboard :3

    Please login or register to view links
     
  4. WarOfRen

    WarOfRen Leecher

    Reputations:
    0
    Joined:
    Aug 3, 2015
    Posts:
    8
    Likes Received:
    0
    Trophy Points:
    0

    Ugh...

    C++ pla d maconvert :/
    hehehe pwede pa hingi ng vb.net or C# code :)
     
  5. trismund

    trismund King in the East
    Staff Member Administrator SF1 VIP

    Reputations:
    378
    Joined:
    Oct 28, 2012
    Posts:
    2,787
    Likes Received:
    444
    Trophy Points:
    0

    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)
           Me.Show()
           KB.Acquire()
       End Sub
    
    
       Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
           KB.Dispose()
           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
    
     
  6. trismund

    trismund King in the East
    Staff Member Administrator SF1 VIP

    Reputations:
    378
    Joined:
    Oct 28, 2012
    Posts:
    2,787
    Likes Received:
    444
    Trophy Points:
    0

    Pwede yan kahit ilang features, depende sa code mo.
     
  7. WarOfRen

    WarOfRen Leecher

    Reputations:
    0
    Joined:
    Aug 3, 2015
    Posts:
    8
    Likes Received:
    0
    Trophy Points:
    0

    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 :/
     
  8. WarOfRen

    WarOfRen Leecher

    Reputations:
    0
    Joined:
    Aug 3, 2015
    Posts:
    8
    Likes Received:
    0
    Trophy Points:
    0

    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)
     
  9. trismund

    trismund King in the East
    Staff Member Administrator SF1 VIP

    Reputations:
    378
    Joined:
    Oct 28, 2012
    Posts:
    2,787
    Likes Received:
    444
    Trophy Points:
    0

    getasynckeystate na try mo na?
     
  10. WarOfRen

    WarOfRen Leecher

    Reputations:
    0
    Joined:
    Aug 3, 2015
    Posts:
    8
    Likes Received:
    0
    Trophy Points:
    0

    Hindi pa, try ko plang.. :cool:
     
  11. WarOfRen

    WarOfRen Leecher

    Reputations:
    0
    Joined:
    Aug 3, 2015
    Posts:
    8
    Likes Received:
    0
    Trophy Points:
    0

    Sir trismund :confused:

    pwede ba download kayo nito : Please login or register to view links
    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 :)
     
  12. WarOfRen

    WarOfRen Leecher

    Reputations:
    0
    Joined:
    Aug 3, 2015
    Posts:
    8
    Likes Received:
    0
    Trophy Points:
    0

    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 :)
     
  13. WarOfRen

    WarOfRen Leecher

    Reputations:
    0
    Joined:
    Aug 3, 2015
    Posts:
    8
    Likes Received:
    0
    Trophy Points:
    0

    [​IMG]
    Ito sir...

    system.runtime.remoting.dll
    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
  14. trismund

    trismund King in the East
    Staff Member Administrator SF1 VIP

    Reputations:
    378
    Joined:
    Oct 28, 2012
    Posts:
    2,787
    Likes Received:
    444
    Trophy Points:
    0

    Susubukan ko pag may time. hindi na kasi ako masyado gumagamit ng Visual Basic
     
  15. steb

    steb Coach

    Reputations:
    0
    Joined:
    Nov 15, 2016
    Posts:
    215
    Likes Received:
    66
    Trophy Points:
    0

    Detected ba to ng xigncode3 ? ginamit ko ung proxycall ni silverdeath gumana .
     

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Share This Page

Pinoy Hideout iHax Community