0
votes

Consider the following assignment: When I type - followed by a key, the result is Ctrl-key. This work for ordinary keys. But when the key is whitespace, it does not work.

Any idea why this happens? And how to fix the code?

-::
Input, key, L1,{LCtrl}
send, ^{%key%}
return

Edit. Try to run the above script a program which has Ctrl-Space as a shortcut to see that it does not work. In fact, if you press - followed by Space, the script is suppose to call Ctrl-Space but it is not the case. For example:

  • In Microsoft Excel or in Libreoffice Calc, Ctrl-Space can select the current column.
  • In Emacs Ctrl-Space is reserved for setting a Mark.
1
I'm unable to replicate this error with the Space, Tab, or Enter keys, but from the Input docs: "Whitespace characters such as Tab (`t) are stored literally. Enter is stored as linefeed (`n)." Could you possibly give us specific examples of keys that do not function correctly?Spyre
@Spyre I added some explanations to replicate the error.Name
Space is one of the default terminator characters, just like Tab, Enter, etc. Change de default to not include space.Robert Ilbrink
@RobertIlbrink, Does not work even if I specify Endkeys. For example I modified the code in order that LCtrl is the only Endkey, but it does not work either. See the modified code above.Name
You are right. I tried your script with the verification line: MsgBox,,,"%key%" just before the send line. This confirms that the space is being read and stored in the key parameter. So the problem is in the send line...Robert Ilbrink

1 Answers

1
votes

Use SendInput instead.

Tested in Excel to mimic ^a, ^x, ^v, ^space

-::
Input, key, L1,{LCtrl}
SendInput, ^%key%
Return

If you want to handle "special" keys, add those keys to the list of endkeys using this syntax

Input [, OutputVar, Options, EndKeys, MatchList]

And then check to see which endkey was pressed

Tested in Firefox to mimic ^PgDn, ^PgUp

Input, key, L1,{LCtrl}{PgUp}{PgDn}
If (ErrorLevel = "EndKey:PgUp") {
  SendInput ^{PgUp}
}
Else If (ErrorLevel = "EndKey:PgDn") {
  SendInput ^{PgDn}
}
Else If (ErrorLevel = "EndKey:LCtrl") {
  Return   ;assumed you just want to abort input with the control key
}
Else {
  SendInput, ^%key%
}
Return