0

i am using following code to send keys to a certain application, but on some PCs its not working. The code itself should be OK, since on most computers it works fine. Its just on some computers that it doesnt work. It sends the keys too many times or doesnt send them at all. After googeling i found that it is a comon problem with some motherboards so i would like to implement a more reliable code that does the same.

UPDATE: INPUTSIMULATOR is not an option because it doesnt work with my code since i have to set another window active. (just tested it)

How could following code be achived in a more reliable way?

    ....
    Key = Sender.Tag
    If Key = "{SPACE}" Then Key = " "

    SetActiveWindow(Form1.activewin)

    If IsNumeric(Key) Then
        SendKeys.Send(Key)
    Else
        SendKeys.Send(Special & IIf(CapsLock.Checked, UCase(Key), Key))
    End If

    Application.DoEvents()

    ....

thanks

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
sharkyenergy
  • 3,842
  • 10
  • 46
  • 97
  • 1
    Maybe this helps: http://stackoverflow.com/questions/5028872/sendkeys-alternative-that-works-on-citrix?rq=1 – Micha May 23 '13 at 07:30
  • thanks, but input simulator doesnt work in my case because i have to write the text to anotehr window. just updated the main post. thanks! – sharkyenergy May 23 '13 at 07:47
  • Is the window part of your project or from a different process? – tinstaafl May 23 '13 at 08:05
  • If it's a different process the [Process Class](http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.process%28v=vs.100%29.aspx), will allow you to override the standard input. – tinstaafl May 23 '13 at 08:13
  • a differnt process. sorry i am a newbie could you please explain a little bit about the process class what oyu mean? – sharkyenergy May 23 '13 at 08:24
  • form1.activewin is a variable contianing the handle of the window i want to write to. the above code works fine, but if i replace sendkeys with the inputsimulator it dosnt work anymore. the targetwindow doesnt get active.. – sharkyenergy May 23 '13 at 08:33

1 Answers1

0

solved by using inputsimulator and adding SetForegroundWindow(Form1.activewin) in front of SetActiveWindow(Form1.activewin)

sharkyenergy
  • 3,842
  • 10
  • 46
  • 97