0

I have an application that closes (crashes?) when SendKeys() sends it a SHIFT keystroke. The shift key could be invoked by simple shift character, +, a capital letter or indirectly by sending a secondary key such as @. In any of said cases, the app will close. This is a third party application so I cant fix their code.

I worked around the capital problem by inserting {CAPSLOCK}. That doesn't solve the secondary key problem. Is it possible to have SendKeys send special characters without invoking Shift? The characters: !@#$%^&*(){}|:"<>?

[Perhaps by converting them to a unicode representation first or something. I don't want to map all of those characters to Unicode manually. Not sure if underlying code will still tap SHIFT]?

UPDATE
Here's the code as requested.

SetForegroundWindow(windowHandle);
string keySequence = stringVariable + "{TAB}" + "aa";//works fine
//string keySequence = stringVariable + "{TAB}" + "a+a";//crash
//string keySequence = stringVariable + "{TAB}" + "aS";//crash
//string keySequence = stringVariable + "{TAB}" + "a@";//crash
SendKeys.SendWait(keySequence);
AstroCB
  • 12,101
  • 20
  • 56
  • 70
P.Brian.Mackey
  • 41,438
  • 63
  • 228
  • 337
  • Is the other application written in .net ? – digEmAll Apr 19 '12 at 16:45
  • @digEmAll - Some of it is, other parts are C/C++. – P.Brian.Mackey Apr 19 '12 at 16:46
  • 1
    I don't know if its feasible for you, but you could use SendMessage windows API to send directly the desired text instead of keys. Have a look [here](http://stackoverflow.com/questions/523405/how-to-send-text-to-notepad-in-c-win32) for an example about how to send text to notepad. – digEmAll Apr 19 '12 at 17:06
  • Could you post the code that's actually doing the sending? I have a spreadsheet that uses SendKeys but haven't had a problem with the Shift key that I can think of. – Ryan O'Neill Apr 19 '12 at 19:00
  • @RyanO'Neill - Done, but I dont think it will help. The code works fine with Notepad. It's just this third party app that closes itself. – P.Brian.Mackey Apr 19 '12 at 19:07
  • Ah sorry, did not catch that part. – Ryan O'Neill Apr 19 '12 at 19:12
  • 1
    Not sure whether it will be any better, but it might be worth having a look at http://inputsimulator.codeplex.com/ – sgmoore Apr 19 '12 at 19:38
  • Maybe this is a stupid question, but does the application even take those characters from others sources? Maybe there is a C++ sample you could maybe re-use yourself to send the keys... – Schwarzie2478 Aug 30 '14 at 20:45
  • What is the exact error on which the application crashes? Maybe you can attach to the application and try to figure something out about the error. No easy but you never know... – Schwarzie2478 Aug 30 '14 at 20:48

0 Answers0