[.net] Simulate Keypress and Directx

Started by
23 comments, last by novice4ever 17 years, 5 months ago
ok will play with this some. i did notice you didn't use a fixed layout on the struct that could cause crashing issues some times. will play with it then post what i get out of it. thanks again
- The collective intelligence of the human race is a constant; the population is growing at an exponential rate. The conclusion is left as an exercise for the student.
Advertisement
do you use the directx key codes? that your enum from Key?
- The collective intelligence of the human race is a constant; the population is growing at an exponential rate. The conclusion is left as an exercise for the student.
working on a parse engine for your key input. should be able to send a string such as "{ENTER}press these keys then enter{ENTER}" and it would send this enter then it would type in 'press these keys then enter' then it would hit enter again.
should be usefull make it possible to send not just single keys easilly but also full strings. trouble is in the {ENTER} or {{} type stuff so you can send anything even special keys hehe.
- The collective intelligence of the human race is a constant; the population is growing at an exponential rate. The conclusion is left as an exercise for the student.
Yeah, Key is the Microsoft.DirectX.DirectInput.Key enum.
ok still fiddleing with it but so far i can send keys. i actually have to send a keydown then a keyup (keydown code is 0 by the way you don't have that one on your enum hehe) working on a buffered pulsed input script. so when you type in 'send all of this{ENTER}' it will send these keys 'send all of this' then hit enter. one big deal is that with your system your currently sending a key ata time in the buffer. if you try to send a stirng of text there is the possibility of someone sneaking in a key press while it's sending it. the solution i'm looking at is to search through the string for my insertion codes such as {ENTER} and replace it with one of the higher ascii codes then when it builds the array of key combos it searches through each key one at a time in the list parses them and converts them to the propper enums then sends the full buffer at once. sound good? and would you be interested in a copy of this code when i'm done? should make that switch case thing absolete or at least make it a little more intuitive to use. =D once again thanks for the assistance on this one. was driving me NUTS hehe
- The collective intelligence of the human race is a constant; the population is growing at an exponential rate. The conclusion is left as an exercise for the student.
Hey, this is great guys. You're right in that there are other people struggling with this. I use the SendInput function and it doesn't seem to work in most games. If you finish that library I'd be really interested. Keep us updated.
Just another thought (it probably doesn't make much of a difference, since your looking into a way to do it without a lookup table). In my code, instead of using a big switch statement to look up scancodes, I just load a map with all the data that's needed. Works mighty fine.
sure but eventually somewhere you must map one thing to another thing. i am using a hashcoded array to do it (the char code is the index of where the directx code is) this means there is a nice one to one relation AND none of that stupid switch case thng (which converts to a long string of if else blocks) this means also that if things change i need only change the mapping.
- The collective intelligence of the human race is a constant; the population is growing at an exponential rate. The conclusion is left as an exercise for the student.
Dear LostAgain,Daggett and KGodwin,
I have read your topic relate to sendkey to directx apps.
http://www.gamedev.net/community/forums/topic.asp?topic_id=419710&whichpage=1
Knowing that you already done that. I have done the same, but it doesnt works (it works on normal windows). It would be nice if you could show me what i have wrong. I just want to simply send a key 0 to the game.
Btw the game I'm testing is 9 Dragons, you can found it here http://nine.nexon.com . And here is my code:

INPUT[] InputData = new INPUT[1];

//KEYBDINPUT:
InputData[0].type = 1;
InputData[0].wVk = 0;
InputData[0].wScan = 0;
InputData[0].dwFlags = 0;
InputData[0].time = 0;
InputData[0].dwExtraInfo = (UIntPtr)0;

int i=0;
while(i<30)
{
InputData[0].wScan = (ushort)'0';
InputData[0].dwFlags = (uint)SendInputFlags.KEYEVENTF_SCANCODE | (uint)SendInputFlags.KEYEVENTF_KEYDOWN;

SendInput(1, InputData, Marshal.SizeOf(InputData[0]));

InputData[0].wScan = (ushort)'0';
InputData[0].dwFlags = (uint)SendInputFlags.KEYEVENTF_SCANCODE | (uint)SendInputFlags.KEYEVENTF_KEYUP;

SendInput(1, InputData, Marshal.SizeOf(InputData[0]));

Thread.Sleep(1000);
i++;
}

Thank you very much for your concert,
Iam sorry for my bad english. Hope to hear from you soon.
Best regards.


Well, your sending '0' as the scan code, when Microsoft.DirectX.DirectInput.Key.D0 (11) is the real scan code for '0';

This topic is closed to new replies.

Advertisement