• Advertisement
Sign in to follow this  

DirectInput, ApiHijack, and VB.Net

This topic is 4288 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I was trying to write some kind of voice-enabled app , to interact with DirectX, when I found this topic by Muhammad Haggag in this forum: http://www.gamedev.net/community/forums/topic.asp?topic_id=371104 Now the problem is that, though the sample work fine, I can't import the library "DirectInput-Hook.dll" to my VB.Net project. Wish someone could help me. I think it must be a simple question, but Visual Studio says "This file is not valid[...]not a COM object". Thanks in advance :)

Share this post


Link to post
Share on other sites
Advertisement
You can't import the DLL because it's not a COM object (doesn't implement a COM server). Use PInvoke. For example, in C# (off the top of my head):

public class InputHook
{
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("DInputHook.dll", EntryPoint="InstallHook", CharSet=CharSet.Auto)]
public static extern void InstallHook();

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("DInputHook.dll", EntryPoint="RemoveHook", CharSet=CharSet.Auto)]
public static extern void RemoveHook();
}

Share this post


Link to post
Share on other sites
Drat, beaten to it again :)

Anyway, if you get this to work, please post some more info on what you did exactly. I've been working on this too in C#, but somehow calling the InstallHook procedure through .NET PInvoke caused the hook to stop working (properly), even though it works just fine using the native launcher.

Share this post


Link to post
Share on other sites
Ok, now I can use the library. Thank you. :)

I used this code in VB.Net

Public Class InputHook

<System.Security.SuppressUnmanagedCodeSecurity()> Public Declare Auto Sub InstallHook Lib "DirectInput-Hook.dll" Alias "InstallHook" ()
<System.Security.SuppressUnmanagedCodeSecurity()> Public Declare Auto Sub RemoveHook Lib "DirectInput-Hook.dll" Alias "RemoveHook" ()
End Class 'InputHook

But anyway, it still not working. I have the same problem as remigius.

My basic code is something like this:

Private Sub btnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIn.Click

H.InstallHook()

End Sub

Private Sub btnOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOut.Click

H.RemoveHook()

End Sub

Then i have a timer sending keystrokes:

keybd_event(VK_A, 0, 0, 0)
keybd_event(VK_A, 0, KEYEVENTF_KEYUP, 0)

It works with any window, but not with the sample "keyboard.exe".

I'm trying to do it this way:

1- Open my app
2- btnIn (InstallHook)
3- launch "keyboard.exe"
4- button "Create Device" in "keyboard.exe"
(at this point, keyboard.exe should be receiving the keystrokes, beacause the timer is on, but it doesn't)
5- Close "keyboard.exe"
6- btnOut (Remove Hook)

Am I doing something wrong? I've spent a lot of time trying other ways to do it, but none of them worked :(

Thank you again (and sorry for my english...i'm from spain ;) )

Share this post


Link to post
Share on other sites
Unfortunately, I didn't get time to inspect this, and I might not get a chance in the foreseeable future. A unix-style solution to this problem would be to use my launcher from your own program; launch the process when you want it to install the hook and terminate it (or send it a terminating keypress - I don't remember how the launcher worked) when you want to uninstall it.

Share this post


Link to post
Share on other sites
Muhammad, Please do spend sometime on this someday later.
I am interested in it too.
I still haven't figure out how to hook my game.

Share this post


Link to post
Share on other sites
Thank's for your answer and your time Muhammad. Anuway, I'll be aware of this topic. Maybe someone else, can find the answer.

Share this post


Link to post
Share on other sites
I have created a sample simialr to Feadur's case.
I do heard the "BEEP" sound.
I think MyDirectInput8Create must have been called. That's is hook should be successful.
But somehow keybd_event cannot read by DirectInput, I think.

Feadur do you have any new update?

Share this post


Link to post
Share on other sites
Well, I use

keybd_event(VK_A, 0, 0, 0)
keybd_event(VK_A, 0, KEYEVENTF_KEYUP, 0)

to send keystrokes from my application to DriectX

Share this post


Link to post
Share on other sites
Quote:
Original post by Feadur
Well, I use

keybd_event(VK_A, 0, 0, 0)
keybd_event(VK_A, 0, KEYEVENTF_KEYUP, 0)

to send keystrokes from my application to DriectX

You're using my hook sample, right? The whole point of the hook sample is to create special IDirectInput7 devices that create a server pipe and listen on it for incoming connections. I don't see what keybd_event has to do with the scenario.

Share this post


Link to post
Share on other sites
Yes, Muhammad.
Actually, I am waiting your confirmation on using a namedpipe is a must.
I have finished a sample using namedpipe.
May be I can post it out these few days. (After tidy up)

Unfortunately, this does not work with my game as expected.
May be I really have to spend some time on writing my own DInput8.dll

Seems a difficult task for me. I am weak in C/C++ programming.

Share this post


Link to post
Share on other sites
I am using something like:

1- InstallHook function
The process name is stored on the registry.

2- Then I send keystrokes to test if the hook is working

3- Finally, I use RemoveHook function to release the device.

I use the sample app "Keyboard.exe" to test it.

Share this post


Link to post
Share on other sites
So, when I create device from the "Keyboard.exe" sample, I hear the sound telling the hook is succesfully intalled, but when I send keystrokes from my app, using de function:

Declare Function keybd_event Lib "user32" Alias "keybd_event" _
(ByVal bVk As Byte, ByVal bScan _
As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) As Long

, "keyboard.exe" doesn't receive anything. May be the problem is in sendin keystrokes usin ths API, but I know no other way to do it.

Share this post


Link to post
Share on other sites
Quote:
Original post by fredkwok
Yes, Muhammad.
Actually, I am waiting your confirmation on using a namedpipe is a must.
I have finished a sample using namedpipe.
May be I can post it out these few days. (After tidy up)

Yes, that's really the whole point. We "hook" DInput in order to be able to create these special devices that listen on the pipe. As such, keybd_event and all similar keystroke-sending functions won't work. You have to connect to the pipe and send your strokes.

Didn't I make this obvious in the DInput hook thread? (Might have to revisit it and edit it if that's the case)

Share this post


Link to post
Share on other sites
Yes, Muhammad, you did a very good sample. I know communicate with a pipe is required.
But when Feadur mention he use keybd_event earily in this post.
You didn't keybd_event was not working. I wonder, there may be a solution with keydb_event.
Since using namedpipe in VBNET seems not an easy job, I will prefer other machanism.
Anyway, finally i did it using some code sample from other to manipulate the namedpipe communication.
It works fine now.

Share this post


Link to post
Share on other sites
fredwok, could you share that sample?

I've been trying a client pipe sample, modifying it to connect to "DInput-Pipe", but it doesn't works. Maybe I'm doing something wrong, or maybe that sample doesn't work :(

Here's my e-mail for you if you have the chance to send me that code you're using. Or maybe ypu can post here the website where you downloaded it.

Thanks

Share this post


Link to post
Share on other sites
Feadur, Currently I am finding good webspace to host my sample.
This forum do not allow attachment.

If I remember correctly, the pipename should be 'DInput-Hook' not 'DInput-Pipe'

Hope this help

Share this post


Link to post
Share on other sites
I've tried with both "DInput-Hook" and "DInput-Pipe", and none of them worked.

Could you please send it to me to morgothfeadur@hotmail.com ?

Thanks

Share this post


Link to post
Share on other sites
woh! Finally it works :)

Not in the game y was trying to use, but that might be a matter different DirectX versions.

Really thank's to Muhammad and fredwork :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement