SendKeys to another running application

  • Thread starter Thread starter bat sar
  • Start date Start date
B

bat sar

Hi all
I'm working on Visual C# .NET, I'm new and I want to build on-screen
keyboard, I want to know what should happen when you click a button,
lets say its "A" how should I send the value of it to another running
application, let it be Word or any other programm... I found somthing
about SendKey.Send ... but I donno how to use it, I tried to read some
about it, but they said that I have to use the FindWindow, to find the
active progrram, so that the key is sent to it, but I couldn't find
anything called FindWindow.
Please if you can help me, I would appreciate it ...
Best regards
Batoul
 
Hi bat sar,

FindWindow is part of the Win32 API (user32.dll).
You need to put something like this to be able to use it (DllImport is
part of System.Runtime.InteropServies)

[DllImport("user32.dll")]
public static extern int FindWindow(string WindowClassName, string
WindowName);
 
Hi,

FindWindow is part of the win API you need to P/Invoke it.

Another problem will be find the target window (application), cause when
you are using your keyboard the active application will be your keyboard
application :)

Cheers,
 
You're could write something at the lower level...

I believe that you could send a system message that alerts that a
keyboard button has been pressed. Put this in a library, and all you'd
have to do is use P/Invoke to use it. This would essentially be
disguising your app as the keyboard itself.

This would also let you handle things like ALT+TAB and the three finger
salute.
 
Well, thank you all for help, I tried to use the FindWindow, and
GetForeGroundWindow, and it worked I got the most top running program
other than my keyboard app ...
but the problem here, is finding away to write into this app, I tried to
send the key directly but it didn't work ...
Do any one know how??? I would appraciate it :)
Thanx again
Batoul
 
Back
Top