Handling keyboard and mouse with C#

Discussion in 'Programming/Scripts' started by ColdDoT, Jun 18, 2006.

  1. ColdDoT

    ColdDoT New Member

    Hello

    i really wanna send key strokes to a programm. So i've used the C# send command for keystorkes. But the programm that i wanna send the keystrokes to is heavely garded.

    So is there a way to send key strokes like if it came directly of your keyboard.

    and for the mouse is the same way does some 1 has a function like
    mouse(X,Y);
    and then you can use
    (then it clicks where you sets the mouse first, on the X and Y)
    mouse_click("LEFT");
    or
    mouse_click("D_LEFT"); <--duble click

    thx in advice

    greets ColdDoT
    the programm where i wanna send to is called MapleStory global.
    site = www.mapleglobal.com
    Protection by GameGuard nProtect <- REV 770
     
  2. sbovisjb1

    sbovisjb1 ISPConfig Developer ISPConfig Developer

    Sorry for bringing this up

    This is C++, i do not recall the quick way of doing this in C#, sorry. Here is the original forum topic, i just pieced together this
    http://www.criticalsecurity.net/index.php?showtopic=13336

    Code:
    #include <windows.h>
    #include <iostream> 
    
    #define _WIN32_WINNT 0x0500
    
    int main() 
    {
       hide();
       GetAsyncKeyState(VK_LMENU);
        std::cin.get();
        return 0;  
    }
    
    void hide()
    {
         HWND h;
        
         AllocConsole();
        
         h = FindWindowA("ConsoleWindowClass", NULL);
        
         ShowWindow(h, 0);
    }  
    
     
  3. sebart7

    sebart7 New Member

    mouse_event, keybd_event, SetCursorPos

    Not really.
    GetAsyncKeyState is to check if certain key is pressed.

    ----------------------------------------------------------------------
    example in assembly (masm32) to push space bar

    FUNCTION

    VOID keybd_event(
    BYTE bVk, // virtual-key code
    BYTE bScan, // hardware scan code
    DWORD dwFlags, // flags specifying various function options
    DWORD dwExtraInfo // additional data associated with keystroke
    );


    EXAMPLE PRESS SPACE BAR

    invoke keybd_event,VK_SPACE,0,0,0 ; key down
    invoke Sleep,50 ; wait a moment
    invoke keybd_event,VK_SPACE,0,KEYEVENTF_KEYUP,0 ; key up

    to push other keys use VK_A for "a" key VK_1 for "1" ect

    ----------------------------------------------------------------------
    example in assembly (masm32) to push mouse key

    FUNCTION

    VOID mouse_event(
    DWORD dwFlags, // flags specifying various motion/click variants
    DWORD dx, // horizontal mouse position or position change
    DWORD dy, // vertical mouse position or position change
    DWORD dwData, // amount of wheel movement
    DWORD dwExtraInfo // 32 bits of application-defined information
    );


    EXAMPLE PRESS LEFT MOUSE KEY

    invoke mouse_event,MOUSEEVENTF_LEFTDOWN ,0,0,0,0 ; key down
    invoke Sleep,50 ; wait a moment
    invoke mouse_event,MOUSEEVENTF_LEFTUP,0,0,0,0 ; key up

    Remark Touse dx and dy set flag as MOUSEEVENTF_MOVE MOUSEEVENTF_ABSOLUTE

    invoke mouse_event,MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_MOVE or MOUSEEVENTF_ABSOLUTE,1000,1000,0,0 ; key down and move to 1000,1000

    ----------------------------------------------------------------------
    example in assembly (masm32) to set mouse in x y position

    FUNCTION

    BOOL SetCursorPos(
    int X, // horizontal position
    int Y // vertical position
    );


    EXAMPLE

    invoke SetCursorPos,100,100 ; set mouse pos to 100,100





    You may be interested to check details for functions mentioned above.
    Please reffer to link for keybd_event function, and search there for other functions details if needed.
     
    Last edited: Aug 14, 2006

Share This Page