My game-monitor app supports simple autofire hotkeys.
A hotkey to toggle the autofire on and off, and another key to send to the game repeatedly until toggled off.
(with specified interval between keys, and notification beeps as the keys are toggled on and off).
Not hard to do.
But I did not want my user to have to learn any special syntax for naming the keys.
So I use a hotkey control to enter the toggle hotkey, with an extra checkbox for the # modifier. (windows key)
That gives me a key in the right form for making a hotkey.
But if I do the same for the key to send, it is not in the right form for sending input to the game.
Instead of "!F3", I need "!{F3}", for example.
Is there some easy built-in way to convert from hotkey syntax to send syntax?
Or do I have to parse the key from the hotkey box and figure out how to recode it?
If I do need to do it myself, is there an easy way to do that?
convert hotkey syntax to send input syntax?
Re: convert hotkey syntax to send input syntax?
You could use A_ThisHotkey to identify the key name. The trick will be with incorporating modifiers. If it's possible someone uses !^::, you have to consider that the right most character which would normally be a modifier in this case is not, and that it's someone pressing Alt+Shift+6 -- though that may not even be possible in the Hotkey control so it shouldn't be a problem. What I would suggest is using RegExMatch/Replace to identify where the +!#^ symbols are, and put brackets around the remainder. I'm sure it can be done in RegExReplace, but I'd have to play around with it to know what.
Though, that may not be the full solution. I'm not sure you can do this and have it work as you expect:
You can see if that works to bring up the typical Save As window in like a word document. If it does, I guess you can just set the value of var through the RegEx as I mentioned before.
Though, that may not be the full solution. I'm not sure you can do this and have it work as you expect:
Code: Select all
var:="^+s"
Send %var%
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: convert hotkey syntax to send input syntax?
The following will work with anything that has only one literal key, unless there is a delimiter (I don't know if the control adds delimiters between non-modifier keys).
Code: Select all
; Example
msgbox % hotkeyToSend("!F3")
; Function
hotkeyToSend(hotkey){
return regExReplace(hotkey,"\w+","{$0}")
}
Re: convert hotkey syntax to send input syntax?
The control (which is a standard Windows control) does not support custom combinations. It does not even support all standard combinations.
Here's another version which handles more hotkeys (that the control will never output):It doesn't distinguish between left and right ctrl/alt/shift/win; just strips out any modifiers that don't have meaning to Send.
Here's another version which handles more hotkeys (that the control will never output):
Code: Select all
MsgBox % HotkeyToSend("$$") ; The second "$" is not a modifier.
MsgBox % HotkeyToSend("~left & up")
MsgBox % HotkeyToSend("<!enter")
MsgBox % HotkeyToSend("*^lbutton up")
HotkeyToSend(hotkey, format := "{$0}") {
if RegExMatch(hotkey, "(.*)[ `t]&[ `t](.*)", m)
return HotkeyToSend(m1, "{$0 down}")
. HotkeyToSend(m2)
. HotkeyToSend(m1, "{$0 up}")
return RegExReplace(RegExReplace(hotkey, "\w+(?i:[ `t]up)?|\W$", format), "(?<!{)[~$*<>]")
}
Re: convert hotkey syntax to send input syntax?
Thank you all.
I'm more interested in keeping it simple for the user than in supporting all key combinations... my user will just have to use something that does not produce "none" in the control.
The control only produces one key. Pressing a second one replaces what is there. So the question of delimiters between multiples does not arise.
I think that means that the simpler regex given by @Masonjar13 should suffice?
I'm still pretty fuzzy about a lot of details here
I'm more interested in keeping it simple for the user than in supporting all key combinations... my user will just have to use something that does not produce "none" in the control.
The control only produces one key. Pressing a second one replaces what is there. So the question of delimiters between multiples does not arise.
I think that means that the simpler regex given by @Masonjar13 should suffice?
I'm still pretty fuzzy about a lot of details here
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: convert hotkey syntax to send input syntax?
I figured as much. I've never actually used it myself, though, didn't know for sure.lexikos wrote:The control (which is a standard Windows control) does not support custom combinations. It does not even support all standard combinations.
I believe so, yes. I'll explain it a bit.wdmodlin wrote:I think that means that the simpler regex given by @Masonjar13 should suffice?
In my code, I simply specify that it should find a word/an alphanumeric character (\w) of any length (+), and replace all of them with the found substring ($0) with added brackets around it; it's replacing the text with the same exact text, plus the brackets. And since it's a function, I have it return the new string, of course.
Re: convert hotkey syntax to send input syntax?
It will not necessarily be sufficient. For instance, on the French keyboard layout there is a key which produces ^ when typed into the hotkey control. You cannot send ^ without wrapping it to {^}. My code automatically handles this case by {wrapping} any single non-word character at the end of the hotkey.
Re: convert hotkey syntax to send input syntax?
Even on an English keyboard, what if someone wanted to do a hotkey like ^\ or !.? So lexikos's code would be good even if your intended audience is only expected to use English QWERTY keyboards.
Re: convert hotkey syntax to send input syntax?
There's no need to modify ^\ or !. for sending. That is valid Send syntax.
The problem is only with characters which Send interprets specially, like ! # ^ { }. The hotkey control won't generate hotkeys with these characters on the standard US layout - they would be +2 +3 +6 etc. instead.
Of course, since you can just use the function I posted, there's not much reason to not support these exotic cases.
The problem is only with characters which Send interprets specially, like ! # ^ { }. The hotkey control won't generate hotkeys with these characters on the standard US layout - they would be +2 +3 +6 etc. instead.
Of course, since you can just use the function I posted, there's not much reason to not support these exotic cases.
Re: convert hotkey syntax to send input syntax?
Oh, yeah, I totally forgot the whole purpose that it was the multiple-character-named keys like Space and Enter we needed to worry about. My apologies.
Who is online
Users browsing this forum: balawi28, Bing [Bot] and 240 guests