问题
I am trying to sed a keystroke in vb.net, and my code at the moment is SendKeys.Send("+^(;)")
But unfortunately it won't fire, could anyone tell me why?
回答1:
I don't recommend using sendkeys for anything really. Reason being that you never can guarantee the keystrokes will go where you intend. This is because you are simulating the input as if it were coming from the keyboard, which also ties up your keyboard.
I suggest instead you take the time and learn about the SendMessage api, or the PostMessage api. With these API's you can send messages to specific windows, regardless of what is going on with the keyboard. For instance, if you write a game bot using sendkeys, then you have to leave your computer alone while it runs and hope no unexpected windows pop open. Whereas if you learn the sendmessage api, then you can write a bot that runs in the background while you do other things with your computer.
here are some links to help:
pinvoke - sendmessage api
pinvoke - postmessage api
A list of windows messages constants/hex values/meanings
A nice description on how to use these api's
来源:https://stackoverflow.com/questions/31670128/correct-sendkey-for-ctrl-shift