I guess I will clarify a bit why you shouldnt use SendKeys...
The reason "SendKeys" should not be used in any program is two-fold:
- You can't "Direct/Control" where the KeyPress events are going to go. They will only goto the Active window - which can switch at a moments notice via another window "notifying" or an alt+tab, or a myriad of other reasons. You can "SetActiveWindow" but it can lose focus as said in the previous sentence.
- You can't send Non-Printable Characters or Unicode text... not really functional, eh?
In regards to the first I will give you a worst case scenario to explain why this is a bad thing.
say your application walks the following menus...
[File] [Edit]
[New] [Examine...]
[Exit]
and your code looks like
Now if i lost focus for the split second b/w Alt+F & N and then regain before X -- My application will exit and I will have been wtf pwnt.Code:SendKeys {Alt+F} ' I dont know the alt char b/c im not lame and dont use sendkeys SendKeys {N} SendKeys {Alt+D} ' See: Above SendKeys {X}
Had I used SendMessage to send Menu commands to the window (.. or WM_KEYPRESS events *wink wink*) I would have been perfectly fine - as it sends to the INDIVIDUAL window -- not to whatever window wants to be active.
Reminder: this makes kittens cry. So, please, don't use SendKeys and make the kittens cry.


LinkBack URL
About LinkBacks



Reply With Quote






Don't mess with my wiggle.






