How to program control key combinations only like ^# in AHK?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kklepper
Posts: 24
Joined: 12 Jan 2015, 10:38

How to program control key combinations only like ^# in AHK?

14 Jan 2015, 22:34

On my box with Win 7 64 bit, ^# will turn Speech Recognition on or off. How can this be done with AHK?

Code: Select all

;Send ^#                     ; does not work
;SendPlay ^#                ; does not work
Send ^{LWin}               ; opens the start menu at my box, works with others
SendInput, ^{LWin}       ; opens the start menu at my box, works with others
I guess that AHK waits for some other key in order to react - which does not come. Same as with ^ or # or ! or + alone - it does nothing, which is what is to be expected in these cases, a true reproduction of the corresponding keystrokes.

Or more generally: How to get AHK to send control key combinations no matter what? I don't know of any such combination used in real life, but why not define your own - like +#, !# etc.?
jpginc
Posts: 124
Joined: 29 Sep 2013, 22:35

Re: How to program control key combinations only like ^# in

14 Jan 2015, 22:49

I don't have speech recognition setup but I think this will work

Code: Select all

run , c:\windows\speech\common\sapisvr.exe -SpeechUX
let me know how it goes
kklepper
Posts: 24
Joined: 12 Jan 2015, 10:38

Re: How to program control key combinations only like ^# in

14 Jan 2015, 22:58

jpginc wrote:I don't have speech recognition setup but I think this will work

Code: Select all

run , c:\windows\speech\common\sapisvr.exe -SpeechUX
let me know how it goes
Thank you very much. This command works fine, however it does not solve my problem.

It starts the engine, or rather, as it is started at startup anyway, it shows the annoying little window again -- which I don't want to see at all, whence I minimize this window after startup to the tray icon bar.

From the tray I used to activate and deactivate the engine with mouse clicks, rather tediously, until I found out that I could stop it by speech command (very important if you are disturbed by people entering the room talking to you and expecting you to respond immediately).

Then, via a journalist, I learned about the hotkey ^# which is even better. Combining this with AHK would be perfect.

As showing this WSR window does not change it's status, your command is no solution to my problem. There seem to be no options to this command.

With them a solution might be possible along your path - we would need options to define the status and an option to define the visibility. Googling didn't show anything of interest, however.
lexikos
Posts: 9621
Joined: 30 Sep 2013, 04:07
Contact:

Re: How to program control key combinations only like ^# in

15 Jan 2015, 01:46

To AutoHotkey, ^# means Ctrl and the hash symbol. # is only a modifier (win key) symbol when it modifies some other key. ^{LWin} is the correct way to send it, and as you said, it works on other boxes. Does manually pressing Ctrl+LWin work on yours?
kklepper
Posts: 24
Joined: 12 Jan 2015, 10:38

Re: How to program control key combinations only like ^# in

15 Jan 2015, 08:26

lexikos wrote:To AutoHotkey, ^# means Ctrl and the hash symbol. # is only a modifier (win key) symbol when it modifies some other key. ^{LWin} is the correct way to send it, and as you said, it works on other boxes.
Thank you for the clarification.
lexikos wrote: Does manually pressing Ctrl+LWin work on yours?
Yes, of course, no problem, otherwise I wouldn't have tried to AutoHotkey it.
kklepper
Posts: 24
Joined: 12 Jan 2015, 10:38

Re: How to program control key combinations only like ^# in

15 Jan 2015, 11:05

I confess I use classic shell - maybe this is why SendInput, ^{LWin} does not work for me. Uninstalling classic shell for a test seems to be overkill, so let me first ask: could that be?
kklepper
Posts: 24
Joined: 12 Jan 2015, 10:38

Re: How to program control key combinations only like ^# in

15 Jan 2015, 15:53

Reading the help file, I discovered debugging methods using KeyHistory:

Code: Select all

Pause::
SendInput, ^{LWin}
KeyHistory
return
produced the follwing output

Code: Select all

VK  SC	Type	Up/Dn	Elapsed	Key		Window
-------------------------------------------------------------------------------------------------------------
13  045	 	d	11.33	Pause          	PSPAD-utf8.ahk - SciTE4AutoHotkey
5B  15B	i	d	0.00	LWin           	
5B  15B	i	u	0.00	LWin       
Now this looks like ^ is not sent at all which explains the behaviour (LWin first down -d-, then up -u-). Hey!

Reading further (Special Keys):
NOTE: Some keys do not generate events and thus will not be visible here. If this is the case, you cannot directly make that particular key a hotkey because your keyboard driver or hardware handles it at a level too low for AutoHotkey to access.
This is interesting. I use a very special keyboard, as far as I know the only one with these features, being long out of production (Chicony KB-108), using a special keyboard driver everybody who owns this keyboard is looking for and has to reinstall it on a new machine (like me). Fortunately there was a nice guy who had one and put it online. :thumbup:

KB-108 has keys for ^x, ^c, ^v, which makes it very handy for my work (for example editing this text). When I noticed that it is no longer produced and none other has these features, not even from Chicony, I hunted for them at eBay and own a dozen of them now which should last until my end here on earth. :D

By the way, none of them ever let me down yet, the first, being in use since about 10 years, has had contact problems with those keys, but they are gone since I have ample spares. :crazy:

Let's see if this is the cause of my behavior. An interesting hint here is that those hotkeys don't work in Scite4AutoHotkey. I try to force the Ctrl key this way:

Code: Select all

Pause::
SendInput, {Ctrl down}{LWin down}{LWin up}{Ctrl up}
KeyHistory
return
Nope, this produces crap:

Code: Select all

01  000	a	d	3.78	LButton        	D:\data\dl\PSPAD-utf8.ahk - AutoHotkey v1.1.16.05
01  000	a	u	1.15	LButton        	
No way. Another attempt:

Code: Select all

Pause::
;ControlSend, Pause, {Ctrl down}{LWin down}{LWin up}{Ctrl up} ; no way, doesn't work either
SendInput, {Ctrl down}
SendInput, {LWin down}
SendInput, {LWin up}
SendInput, {Ctrl up}
KeyHistory
return
That's it!

Code: Select all

13  045	 	d	1.70	Pause          	Kurznotiz                      ; where I started from to test the Pause key
A2  01D	i	d	0.00	LControl       	
5B  15B	i	d	0.00	LWin           	
5B  15B	i	u	0.00	LWin           	
A2  01D	i	u	0.00	LControl       	
Works brilliantly! Omit history:

Code: Select all

Pause::
SendInput, {Ctrl down}
SendInput, {LWin down}
SendInput, {LWin up}
SendInput, {Ctrl up}
return
Finally! Simple solution! Thank you all! :bravo:
kklepper
Posts: 24
Joined: 12 Jan 2015, 10:38

Re: How to program control key combinations only like ^# in

15 Jan 2015, 16:16

When I tried to simplify this by defining a function, I ran into a new problem:

Code: Select all

toggle_wsr() {
SendInput, {Ctrl down}
SendInput, {LWin down}
SendInput, {LWin up}
SendInput, {Ctrl up}
}

Pause::
toggle_wsr()
return
This did not work! It should! Why? :sick:

KeyHistory came to the rescue again:

Code: Select all

13  045	 	d	1.42	Pause          	
14  03A	i	d	0.00	CapsLock       	
14  03A	i	u	0.00	CapsLock       	
A2  01D	i	d	0.00	LControl       	
14  03A	i	d	0.00	CapsLock       	
14  03A	i	u	0.00	CapsLock       	
14  03A	i	d	0.00	CapsLock       	
14  03A	i	u	0.00	CapsLock       	
5B  15B	i	d	0.00	LWin           	
14  03A	i	d	0.00	CapsLock       	
14  03A	i	u	0.00	CapsLock       	
14  03A	i	d	0.00	CapsLock       	
14  03A	i	u	0.00	CapsLock       	
5B  15B	i	u	0.00	LWin           	
14  03A	i	d	0.00	CapsLock       	
14  03A	i	u	0.00	CapsLock       	
14  03A	i	d	0.00	CapsLock       	
14  03A	i	u	0.00	CapsLock       	
A2  01D	i	u	0.00	LControl       	
14  03A	i	d	0.00	CapsLock       	
14  03A	i	u	0.00	CapsLock  
:shock:

Reason for this: I had used CapsLock to easily insert ; for commenting lines out... So make sure CapsLock is Off:

Code: Select all

toggle_wsr() {
SetCapsLockState Off
SendInput, {Ctrl down}
SendInput, {LWin down}
SendInput, {LWin up}
SendInput, {Ctrl up}
}
Works! :dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], wineguy and 141 guests