|
-
Nov 22nd, 2008, 04:36 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2008] Sending text to another application
Hi everyone, I've got a problem.
I'm trying using 'My.computer.Keyboard.SendKeys("0")' to send the text "0" to set the text of an edit control in another application,
it works for NotePad, but not for the application I'm trying to do it with.
I think I know what's wrong, when using Microsoft Spy++ to view the windows of the process, there is only one visible window, and no other windows like edit/button windows etc.. so I think the 'edit' control I see, is actually manually painted, and they're using WM_NCHITTEST and other stuff to determine where the mouse has clicked and what to do...
And it also doesn't act like a normal edit control, IE holding down a key doesn't repeatedly add that key to the text box, you can only remove the last character in the text box etc...
How would I simulate pressing a key on the keyboard? because pressing a key works fine for the application?
Kind Regards
Icyculyr
-
Nov 22nd, 2008, 07:10 AM
#2
-
Nov 22nd, 2008, 07:25 AM
#3
Thread Starter
Frenzied Member
Re: [2008] Sending text to another application
Hi, like I said above, it doesn't work. I don't think the 'edit' control I see is what it seems, I think it's merely the image of a text box painted on the window, and then the window is handling adding the text / displaying it, showing the selection caret etc.. instead of just making an 'edit' control.
So I need to know how to simulate a key press, other than SendKeys.. since pressing a key works, but sending it via my application does not, the application has had focus the time I've been doing as well.
Does anyone have any idea?
Kind Regards
Icyculyr
-
Nov 22nd, 2008, 11:34 AM
#4
Lively Member
Re: [2008] Sending text to another application
What's the program called?
You may want to use SendInput or [Send/Post]Message... (or keybd_event, but thats been replaced by SendInput)
-
Nov 22nd, 2008, 04:59 PM
#5
Thread Starter
Frenzied Member
Re: [2008] Sending text to another application
It's actually a game, forgot to mention that =D
I tried using the SendMessage API with WM_SETTEXT, but that's for setting window title, and that's exactly what it did, I did not try 'PostMessage' nor 'SendInput'... what is SendInput is that an API I have to add?
Kind Regards
Icyculyr
-
Nov 22nd, 2008, 05:25 PM
#6
Thread Starter
Frenzied Member
Re: [2008] Sending text to another application
I actually was going to use SendInput, then I checked out keybd_event, which suited me more, I only want to send the letter '0', only one character...where SendInput looked like it was designed for sending multiple characters as well (I think)
Unfortunately, no success, I went to notepad, I clicked my middle mouse button..which runs the code... (I've setup a hook, so when I click it, it runs the code), the character was put into Notepad, unfortunately in the game, nothing happened.
I'm really not sure why this isn't working.. the main window should receive the text input and add it to the text box! :/
I'm not sure if SendMessage/PostMessage would work, although I'd like to try, but what command do I send? like I said, WM_SETTEXT doesn't work in SendMessage... not sure about PostMessage, never used it before.
Kind Regards
Icyculyr
-
Nov 22nd, 2008, 06:31 PM
#7
Lively Member
Re: [2008] Sending text to another application
Ok, well because its a game, im assuming that its OGL/DX and so using keybd event wont work.
With regards to the settext, you want to use keydown+up
-
Nov 22nd, 2008, 06:48 PM
#8
Thread Starter
Frenzied Member
Re: [2008] Sending text to another application
Can you send those? heh, ya learn a new thing everyday, let me try that..
OGL/DX = Open GL / DirectX?
Kind Regards
Icyculyr
-
Nov 22nd, 2008, 06:58 PM
#9
Thread Starter
Frenzied Member
Re: [2008] Sending text to another application
I don't think you can send the WM_KEYDOWN/KEYUP commands, if you look them up in MSDN they're only referred to as 'notifications' there aren't any examples (that I can find) that actually send the message...
Any idea's?
Kind Regards
Icyculyr
-
Nov 22nd, 2008, 07:15 PM
#10
Lively Member
Re: [2008] Sending text to another application
You can send them. Just use Spy++
Quick example
Private Declare Auto Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
or
Private Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
Public Const WM_KEYDOWN = &H100
then...
PostMessage(hWnd, WM_KEYDOWN, Keys.Y, 0)
-
Nov 22nd, 2008, 08:27 PM
#11
Thread Starter
Frenzied Member
Re: [2008] Sending text to another application
Thanks again for your help, but still it does not work, I've tested it with notepad, works fine, (as long as I use the hWnd to the edit control).
With the game, I used it's only 'visible' window (determined from spy++)...
When I look at it in Spy++, open the initial process, there are only two threads that can be expanded, one at the very front and one at the very bottom of the list.
In the first thread there is 'Window <hWndID> "Game" WINXCLASS
and 'Window <hWndID> "M" MSCTFIME UI' and 'Window <hWndID> 'Default IME'' IME.. in the last thread, there is "DIEmWin" DIEmWin and "Default IME" IME...
All are hidden windows except for the WINXCLASS one, not sure what any of those are, do you have any idea?
Kind Regards
Icyculyr
-
Nov 23rd, 2008, 07:21 AM
#12
Lively Member
Re: [2008] Sending text to another application
Ok, well ive been doing some testing on this...
I found that you can send keystrokes to windows inside of some games (Eg chat, console, etc) but not the the game itself.
Instead of using the normal keys enum (Windows.Forms.Keys) I tried using the DirectX inputs, (Imports Microsoft.DirectX, DirectInput.Key) still with no luck.
You might want to look into using a C++ DLL in order to achieve this as in the past ive seen an example that uses APIHijack to send keys to a DirectX game.
Ill continue looking into this for you though...
(And can you just say what game this is please ^_^)
-
Nov 23rd, 2008, 09:28 AM
#13
Hyperactive Member
-
Nov 23rd, 2008, 10:31 AM
#14
Lively Member
Re: [2008] Sending text to another application
Icyculyr, i was testing earlier, and using SendInput with MOUSEINPUT and Windows.DirectX.DirectInput.Mouse ---> Works.
So, i should think that Keys and KEYBOARD Input would work too, i'll test it out later
-
Nov 26th, 2008, 07:12 AM
#15
Thread Starter
Frenzied Member
Re: [2008] Sending text to another application
Hey thanks a lot for your help TGO, I've decided to give up on this, was more curious than anything, and after a hour or so working on it, that curiosity has subsided lol.
(game was Geneforge 4)
Kind Regards
Icyculyr
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|