Jump to content

Mouse and keyboard input through Direct input 8

- - - - -

  • Please log in to reply
6 replies to this topic

#1
Exempt

Exempt

    Newbie

  • Members
  • PipPip
  • 10 posts
I'm try to find a way to control a game that uses direct input. What I need is info on how to set this up and the best ways to do it. I was hoping not to get to advanced for this project as I'm still learning.

I have tried to use SendInput() a few different ways and I could seem to get that working. Ialso tried to figure out MapVirtualKeys(), that lost me completely. I was told to use MapVirtualKeys() to shift <<16 bits to the left then I could use PostMessage() to make it work. I had 0 luck getting that going. Another big thing was injecting a dll into the program to use DINPUT and that is just way over my head at this point, unless someone can break that down as simple as possible for me.

On a side note, I was hoping o make this so I could multi task while it was sending keystrokes and mouse clicks. Thats would be bst but if thats to complicated I will settle for less to start and add on to it as i start to better understand this kind of programming.

I really just need ideas and maybe a simple code sample.

Thanks, Exempt.


In one post i read regarding my questions it asked whether the program used LoadLibrary()... and if so some function wouldn't work without inject. When I use Dependency Walker I see this for the function name.

DirectInput8Create


#2
julmuri

julmuri

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts

Exempt said:

I was told to use MapVirtualKeys() to shift <<16 bits to the left then I could use PostMessage() to make it work. I had 0 luck getting that going.

Maybe something like:
int GetScanCode( int vk )
{
    return MapVirtualKeyEx( vk, MAPVK_VK_TO_VSC,
         GetKeyboardLayout( GetCurrentThreadId() ));
}


bool PostKey( HWND window, int vk )
{
    unsigned param = GetScanCode( vk );

    param <<= 16;
    param  &= 0x00FF00000;
    param  |= 0x010000001;

    if ( !PostMessage( window, WM_KEYDOWN, vk, param ))
        return false;

    param |= 0xC0000000;

    if ( !PostMessage( window, WM_KEYUP, vk, param ))
        return false;

    return true;
}
Untested code, if it doesnt work you should check that I didnt mess up the lparam bits:
WM_KEYDOWN Message (Windows)
std::string s("oberq zhpu?");std::for_each(s.begin(),s.end(),[&](char&c){c=~c;c=~c-0x01/(~(c|0x20)/0x0D*0x02-0x0B)*0x0D;});std::cout<<s;

#3
Exempt

Exempt

    Newbie

  • Members
  • PipPip
  • 10 posts
I tried and I cannot seem to get anything to pass to this game. The game I'm working with is called Xenimus from Xenimus. It's free to play if you would like to see.

I'm going to try and learn how this works...WH_JOURNALPLAYBACK with hooking. From what i understand though if I use this i will be unable to use the computer for anything else while that hook is working. Hopefully I have that much wrong.

#4
julmuri

julmuri

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts
You should forget windows hooks and hook the dinput factories && interfaces.
DirectInput8Create
IDirectInput8::CreateDevice Method
IDirectInputDevice8::GetDeviceState Method

So first you hook DirectInput8Create and return your own interface from there.
Next, when CreateDevice method is queried on your interface you return your own device.
And lastly, in when client polls keyboard data from your device you inject your own data in there.

There are alot of samples on how to do this if you searh some.
Let me google that for you.
std::string s("oberq zhpu?");std::for_each(s.begin(),s.end(),[&](char&c){c=~c;c=~c-0x01/(~(c|0x20)/0x0D*0x02-0x0B)*0x0D;});std::cout<<s;

#5
Exempt

Exempt

    Newbie

  • Members
  • PipPip
  • 10 posts
I've read a ton of these and samples and forums about how to hook direct input and most are way over my head. So unless you know a source where i can see a very simple di hook and keyboard input setup I don't think this would be an option for me at this point.

#6
julmuri

julmuri

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts
First link from the google seems simple enough. (:
[C++] DirectInput Hooking component and sample - GameDev.Net Discussion Forums

Doesnt get much simpler than that.
std::string s("oberq zhpu?");std::for_each(s.begin(),s.end(),[&](char&c){c=~c;c=~c-0x01/(~(c|0x20)/0x0D*0x02-0x0B)*0x0D;});std::cout<<s;

#7
Exempt

Exempt

    Newbie

  • Members
  • PipPip
  • 10 posts
Thats is way beyond simple. Did you look at it? There is like 2000 files with it non of which i can get to work.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users