Results 1 to 5 of 5
  1. #1
    Coders (+)_'s Avatar
    Join Date
    Jan 2010
    Location
    Earth
    Posts
    459

    Talking Send key input to specific window.

    Hello! How can I send key input to specific window only? I am trying to make a bot for a mmo game and I do not want the desktop to be affected.

    Thanks!

  2. #2
    Coders
    Join Date
    Nov 2009
    Location
    Belgium
    Posts
    990

    Re: Send key input to specific window.

    SendInput is not designed to target to a single window. My best guess, and probably a really bad one, is to set the current window on foreground, do your stuff and restore the active window after.

    Code:
    RECT rect;GetWindowRect( hWnd, &rect );
    HWND prev = GetForegroundWindow( );
    
    
    SetForegroundWindow( hWnd );
    SendInput stuff ...
    SetForegroundWindow( prev );
    Pretty sure there are better alternatives but I'm on my phone now so...

  3. #3
    Coders (+)_'s Avatar
    Join Date
    Jan 2010
    Location
    Earth
    Posts
    459

    Re: Send key input to specific window.

    Okay I made a working project in Win7:

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    void main( void )
    {
    	printf( "Start\n" );
    
    	HWND notepad		= FindWindowA( 0, "Untitled - Notepad" );
    
    	if( !notepad )
    		printf( "Error\n" );
    
    	UINT scanCode		= MapVirtualKeyA( VK_RETURN, 2 );
    	HWND hc				=GetDlgItem( notepad, 15 );
    
    	SendMessageA( hc,WM_CHAR, 'B', 0 );
    	SendMessageA( hc,WM_CHAR, 'a', 0 );
    	SendMessageA( hc,WM_CHAR, 'h', 0 );
    	SendMessageA( hc,WM_CHAR, scanCode, 0 );
    	SendMessageA( hc,WM_CHAR, 'B', 0 );
    	SendMessageA( hc,WM_CHAR, 'a', 0 );
    	SendMessageA( hc,WM_CHAR, 'h', 0 );
    	SendMessageA( hc,WM_CHAR, scanCode, 0 );
    
    	system( "PAUSE" );
    }
    Here is the result:

    Last edited by (+)_; September 28th, 2013 at 13:11.

  4. #4
    Coders
    Join Date
    Nov 2009
    Location
    Belgium
    Posts
    990

    Re: Send key input to specific window.

    Test it out when the window is minimized. Thought it was a security measure.

  5. #5
    Coders (+)_'s Avatar
    Join Date
    Jan 2010
    Location
    Earth
    Posts
    459

    Re: Send key input to specific window.

    This seems to work for mouse in my game:

    Code:
    HWND notepad		= FindWindowA( 0, "My Game" );
    
    DWORD hival,loval;
    			hival		= (195 << 16);
    			loval		= 134;
    			SendMessageA(notepad,WM_LBUTTONDOWN,(WPARAM)0,(LPARAM)loval|hival);
    EDIT:

    I will just hook directinput8.
    Last edited by (+)_; September 28th, 2013 at 17:36.

Similar Threads

  1. QuakeLive and Mouse Input
    By TigerLily in forum Quake Live Cheats
    Replies: 12
    Last Post: July 7th, 2013, 20:15
  2. [Tutorial] Mod Specific WallHack for ET
    By AdawolfA in forum Tutorials
    Replies: 44
    Last Post: October 11th, 2011, 00:52
  3. ET error/ input no supported
    By Makingownserver in forum Windows
    Replies: 0
    Last Post: March 8th, 2010, 23:45
  4. Irritating little window
    By MARK1992 in forum ETH32
    Replies: 8
    Last Post: November 24th, 2007, 15:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •