Jeff Bishop wrote:
Hello,
What would be the best way to insert a key such as
Control-Windows-Numpad-+ as the key name to the InsertKey method? I
would like to pass to a generic function the key name to act on and
have it insert that value in an InsertKey function.
You couldn't have asked this question before 7.1 shipped? <smile>
Unfortunately, it's not a simple matter of passing the string directly
to some method. We've made a note to add something useful to the object
model in the future to make that easier.
For now, you have to use Keyboard.Key to turn the string into a Key
object, then build a KeyModifiers value from the various FilterBlah
properties of the Key object:
Dim km
Dim k
Set k = Keyboard.Key( stringValue )
km = 0
If k.FilterShift = kfsDown Then
km = km + kmShift
End If
If k.FilterControl = kfsDown Then
km = km + kmControl
End If
' et cetera
Keyboard.InsertKey k.Index, km
There's not a strict one-to-one correspondence between the keys that
Keyboard.Key and friends will give you and the keys that you can
insert. For example, InsertKey doesn't attempt to do anything with
numlock, so if you need to deal with NumOn or NumOff you will need to
use InsertKeyDown and InsertKeyUp as needed to toggle it before and
after inserting your key.