 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Jerry
Joined: 24 Jun 2004 Posts: 39
|
Posted: Fri Oct 29, 2004 9:11 pm Post subject: hotstrings activating / not activating with suggestion |
|
|
Chris,
I noticed times when hotstrings should not have executed when I believe they should have.
And other times when they execute when I believe they should not have.
After tracking the problem for a bit, I think the problem is with the way autohotkey determines the start of the hotstring.
I have an application that uses keys RControl, Application, and the function keys. These keys can fool (sometimes)
autohotkey into thinking that the hotstring keys I have entered are in the middle of a word and therefore not executed.
(I do not want to use the ?: option of a hotstring)
For your information, this application has the RControl key functioning like the enter key.
Also I can start to press in the hotstring and then change the position of my cursor with the mouse and continue
to key in the hotstring sequence resulting in the execution of the hotstring. (I feel that it should not have executed under this situation). Also if I change window focus and then return and complete the hotstring while focus is in another window the hotstring executes. I feel that the hotstring should not have activated under this circumstance.
I think of hotstrings to be application specific not system wide.
While thinking of ways to suggest fixes of the perceived problem, I came up with these 4 suggestions. Maybe this should be in the wish list?
1) Command #hotsrting have a new parameter 'StartChars'
eg) #Hotstring StartChars NewChars
2) Expand NewChars to include keys like Lcontrol, appskey, LButton, VKffSC..., Enter, {left 2}, etc
I also included mouse commands and the keys that trigger the combination now, namely, enter.
I suggest this so that the script could have the ultimate control of what keys mark the stop or start of a hotstring.
3) Four script variables , that the script can change.
variables could be =>
A_HotStringCharacter
A_HotStringVKSC <-- is the VKSC's of the
characters in A_HotStringCharacter
A_Not_HotStringCharacter <-- there would have to be a
limit on number of
characters to save. (You might
add a new directive
to be able to play with the limit)
A_Not_HotStringVKSC eg. the VKSC of e is 45 012.
Needs a limit too
4) 3 new hotstrings activation keys
CharacterFound
NotFound
CharacterNotFound
eg. :s:{characterFound}:: ;the 's' stands for special characters
ie. the activation sequence is not raw
eg. script to help clarify the new hotstrings
#perminent
return
:b0:the r::
; standard #1 hotstring
send, ain mainly falls
return
:b0:mer::ry christmas ; standard #2 hotstring
:*b0s:{characterFound}::
; this would get activated after typing in 't', 'th', 'the', 'the '
; or 'm', 'me'
; it would not get triggered on 'the r' or the 'mer'
; a_notHotStringCharacter would be blank
msgbox, So far you have typed %a_hotstringCharacter%
:*b0s:{NotFound}::
; eg. typed in 'tha'
; in this case the a_hotstringCharacter would be 'th'
; and a_not_HotstringCharacter would be 'a'
msgbox, you typed in %a_hotstringCharacter% and then lost focus at %a_not_HotstringCharacter%
:*b0s:{CharacterNotFound}::
; this would be a negative hotstring
; eg. type in any character that did not start the hotstring sequence.
; could be mouse, activity too but not the EndCharacters or the ST
Tooltip, characters not triggering anything are %a_not_HotstringCharacter%
; the command msgbox for this hotstring would not be a good idea!
Return
A bigger script example (to see the possibilities or help the understanding of the ideas) follows.
The idea is to be able to
1) timeout a hotstring
2) clear and reload hotstrings if the window loses focus
3) hotkeys / scripts would be to pause, save, restore hotstrings on
command
window = This Application
SetTimer, watchWindow, 20
SetTimer, TimeOut, 20
;Now if I press the 't' and have not yet pressed the period, my script could
;issue the commands
...
hot_var = %A_HotStringCharacter%
A_HotStringCharacter =
WinActivate, another window
; send keys - wait for reply etc ...
WinWaitActive, %window%
If hot_var <>
{
A_HotStringCharacter = %hot_var%
}
...
ExitApp
; -- hotstring --
:*b0:t.::{left 2}TIS0434.
:*b0s:{NotFound}:
start_time = 0
Return
:*b0s:{CharacterNotFound}:
start_time = 0
Return
:*b0s:{CharacterFound}:
if start_time = 0
{
start_time = %A_TickCount%
}
else
{
elapsed_time = %A_TickCount%
elapsed_time -= %start_time%
if elapsed_time > 20
{
A_HotStringCharacter = ;
start_time = 0
}
}
Return
; -- hotkeys --
~appskey::
A_HotStringCharacter =
send, something
mousemove, x , y
Return
; -- subroutines --
WatchWindow:
; Could watch if the window loses focus due to a window popup or the user switches
; windows in the middle of a string
IfWinNotActive, %window%
{
Suspend, on
hot_var = %A_HotStringCharacter%
A_HotStringCharacter =
}
Return
Timeout:
elapsed_time = %A_TickCount%
elapsed_time -= %start_time%
If Start_time > 0
{
If elapsed_time > 20
{
;time out now
A_HotStringCharacter =
}
}
Return
Jerry |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Fri Oct 29, 2004 10:07 pm Post subject: Re: hotstrings activating / not activating with suggestion |
|
|
| Quote: | | I noticed times when hotstrings should not have executed when I believe they should have. | There was a bug-fix for that in v1.0.21. Are you using an older version?
| Quote: | | For your information, this application has the RControl key functioning like the enter key. | From what you've said it seems likely that RControl is simply interpreted a different way by this particular application (rather than it simulating an Enter keystroke). If that is the case, you might be able to work around the problem by defining RControl as a pass-through hotkey: | Code: | ~RControl::
IfWinNotActive, Special app title
return
; Otherwise, do something to reset the hotstring monitor without disrupting
; the app. Cancel-keys are: arrows, pgup, pgdn, home, enter.
; You could also momentarily activate a different window, send a keystroke
; of any kind, then activate the previous window to reset the hotstring monitor.
Send {right}
return |
| Quote: | Also I can start to press in the hotstring and then change the position of my cursor with the mouse and continue
to key in the hotstring sequence resulting in the execution of the hotstring. (I feel that it should not have executed under this situation). | That's a tough one to handle because all AutoHotkey sees is keystrokes and mouse clicks. It has no idea what those keystrokes and mouseclicks do other than the easy ones such as backspace. For example, you could be clicking on a menu but then cancel the menu and resume typing the hotstring.
Still, maybe an option should be added that makes any mouse click reset the hotstring monitor (so that it begins waiting for an entirely new hotstring). However, this option would require that the mouse hook be installed, either automatically or manually (not sure which is best). Edit: A mouse reset has been added in v1.0.42.03. See "hotstring mouse" for details.
| Quote: | | Also if I change window focus and then return and complete the hotstring while focus is in another window the hotstring executes. I feel that the hotstring should not have activated under this circumstance. | If the window changes and you type even a single character in that new window, the hotstring monitor will reset. However, if you switch windows but return before typing anything in the other window, it doesn't. This is mostly for performance reasons: to do otherwise would require that AutoHotkey constantly watch the active window and reset the hotstring monitor the moment it changes. Still, maybe this is an option that could be added.
I'm guessing you're a heavy user of hotstrings? If so, that is good because yours is probably the only detailed feedback I've yet received from a heavy user. By the way, has anyone else run into the above issues?
| Quote: | | I think of hotstrings to be application specific not system wide. | But you'll admit that some users (probably the majority) prefer system wide hotstrings; perhaps you were only suggesting that this be an option. In any case, you can make your hotstrings context sensitive two ways:
Method #1: On an individual hotstring basis as in this example: | Code: | :b0:btw::
IfWinNotActive, ahk_class MyClass
return
; Otherwise:
Send, {bs 4}by the way
return |
I see now that the above isn't very elegant. So perhaps some built-in context sensitivity is in order, perhaps via window groups.
Method #2: Load a new script every time the active window changes to something that warrants a different set of hotstrings. This can be done automatically as described here: http://www.autohotkey.com/forum/viewtopic.php?t=591
| Quote: | 1) Command #hotstring have a new parameter 'StartChars'
eg) #Hotstring StartChars NewChars
2) Expand NewChars to include keys like Lcontrol, appskey, LButton, VKffSC..., Enter, {left 2}, etc | That sounds good. Perhaps the syntax could be done this way:
~LControl::
~AppsKey::
~LButton::
~Enter::
Hotstring, reset
return
By including a tilde in front of each of the above, the keystrokes are not disrupted in any way; the script merely notes that you pressed the key and performs the subroutine.
| Quote: | | I also included mouse commands and the keys that trigger the combination now, namely, enter. I suggest this so that the script could have the ultimate control of what keys mark the stop or start of a hotstring. | Very good suggestions, thanks. I was also thinking of optionally allowing keys such as down-arrow to be end-keys. For example, if you type a hotstring in a spreadsheet cell and then press down-arrow, it would be nice if the hotstring expanded in the cell before the down-arrow took effect and moved the focus down by one cell.
As for the rest of your post, I'm going to spend a little more time trying to fully understand it. In the meantime, if something comes to mind, feel to reply to anything I've already posted.
Edit: Fixed typo
Last edited by Chris on Tue Feb 21, 2006 2:33 am; edited 2 times in total |
|
| Back to top |
|
 |
Jerry
Joined: 24 Jun 2004 Posts: 39
|
Posted: Sun Oct 31, 2004 5:41 am Post subject: |
|
|
I am running version 1.0.22
| Quote: | | If that is the case, you might be able to work around the problem by defining RControl as a pass-through hotkey |
The script already has ~Rcontrol as a pass-through. However, I believe that the pgdn key is not used so I can use that one as the cancel-key.
| Quote: | | Cancel-keys are: arrows, pgup, pgdn, home, enter |
I find this interesting. Are the cancel-keys observed by autohotkey if I send them using the controlsend command? (Of course it would be to a different window as the app I am having difficulties with.)
For this app it would be nice if I could change the cancel-keys as it would be easer to work with the script. You kind of sold me on
my idea of "#Hotstring StartChars NewChars". With a little extra suggestion (assuming the startchars are different then the cancel-keys)
#Hotstring Cancel-keys NewChars
(for this app the cancel-keys I would assign are, all the function keys, enter, rctrl, home, end, esc, tab, and the arrows but that would be for this app not others.)
| Quote: | | you'll admit that some users (probably the majority) prefer system wide hotstrings |
I agree. I was trying to give you a feel for how I was using them for this application and I was not following the norm by using the hotstrings as system wide ones.
| Quote: | | I'm guessing you're a heavy user of hotstrings? | Yes but most of the hotstrings are for this problem app so they mainly start with :b0:
| Quote: | | can make your hotstrings case sensitive two ways: |
I am using a third method.
Multiple scripts are running at the same time and it is up to each script to
'Suspend' its hotkeys and hotstrings when the window it is controlling does not have the focus.
The General idea is
| Code: |
controlWindow = A app
switch = ; not needed, but reminds me that the variable is being used
SetTimer, Watchwindow, 20
main routine
...
Return
; hotstrings
...
; hotkeys
...
WatchWindow:
ifWinNotActive, %controlWindow%
{ ; suspend all keys if widow is not activate
if switch <> on
{ ; avoid issuing the command when not needed
Suspend, on
switch = on
}
}
else
{ ; window is active turn on the strings and keys
if switch <> off
{
Suspend, Off
switch = off
}
}
Return
|
I like to have mutilple scripts running as my scripts tend to
get complex and the more I can separate them the easier it
is to debug and maintain them. This is why I tend to think of the
hotstrings / hotkeys as being application specific.
Thanks for taking your time to reply to my ideas.  |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sun Oct 31, 2004 12:27 pm Post subject: |
|
|
| Quote: | | I am running version 1.0.22 | Ok. If you ever notice immediately after typing a hotstring that it has not been triggered, please let me know. Note that by default, a hotstring will not fire if it is already running from a previous time. This can be changed via #MaxThreadsPerHotkey (which affects both hotkeys and hotstrings).
| Quote: | | The script already has ~Rcontrol as a pass-through. However, I believe that the pgdn key is not used so I can use that one as the cancel-key. | Even though it already uses RControl, depending on its nature you might be able to give it a dual purpose: to cancel the hotstring process, either by momentarily activating another window and sending it a keystroke.
| Quote: | | Quote: | | Cancel-keys are: arrows, pgup, pgdn, home, enter |
I find this interesting. Are the cancel-keys observed by autohotkey if I send them using the controlsend command? | I realize now that the cancel key idea can't work because the hotstring monitor ignores input generated by any AutoHotkey script. Therefore, the Send command won't help. As you've suggested, I'll look into providing a way to reset it (something less drastic than the Reload command). The Suspend command will reset it if it causes the keyboard hook to be removed and later reinstalled -- this depends on the nature of the script; specifically, whether anything in the script still needs the hook after the hotkeys and hotstrings are suspended.
| Quote: | | I was not following the norm by using the hotstrings as system wide ones. | Your suggestions brought to mind the idea of a filter, perhaps something like this: | Code: | #Hotstring filter MyFilter
::btw::by the way
::otoh::on the other hand
#Hotstring filter ; turn it off for subsequent hotstrings
MyFilter:
WinGetClass, ActiveClass, A
if ActiveClass in notepad,calculator
if A_ThisHotkey in `::btw,`::otoh
ErrorLevel = Yes ; Override the default and allow this hotstring to fire.
return |
Does the above seem like it would be useful? Perhaps not, since you're already using the Suspend command in multiple scripts.
| Quote: | | Multiple scripts are running at the same time and it is up to each script to 'Suspend' its hotkeys and hotstrings when the window it is controlling does not have the focus. | That's a great solution.
| Quote: | if switch <> on
{ ; avoid issuing the command when not needed
Suspend, on | If you feel like simplifying, you don't need to worry about checking if suspend is already on or off because the program does this for you: if it's already in the right state, it does absolutely nothing. This is also true of other similar commands.
| Quote: | I like to have mutilple scripts running as my scripts tend to
get complex and the more I can separate them the easier it
is to debug and maintain them. This is why I tend to think of the
hotstrings / hotkeys as being application specific. | You had said that some of your hotstrings use the b0 (no backspace) option. Because of your use of the Suspend command, I'm curious why you need b0. Perhaps it's because these are not auto-replace hotstrings? |
|
| Back to top |
|
 |
Jerry
Joined: 24 Jun 2004 Posts: 39
|
Posted: Mon Nov 01, 2004 2:29 pm Post subject: |
|
|
I just noticed this problem:
Hope it helps you figure things out.
| Code: |
$appskey::
send,{F9}{home}{RControl}
Return
:b0:js::
send,{home}{end}jesm{Rcontrol}1{Rcontrol}
sleep,10
send,{home}
return
|
Situation:
I press a letter ( not a 'j') and then press the appskey and
then type in js {space}.
The hotstring does not execute even though the {home} key was sent in the hotkey appskey.
P.S. Version of Autohotkey is 1.0.22 for a windows 2000 service pack 4 machine |
|
| Back to top |
|
 |
Jerry
Joined: 24 Jun 2004 Posts: 39
|
Posted: Mon Nov 01, 2004 7:46 pm Post subject: |
|
|
First ignore my last post of 1:29pm I had not seen your reply when I
wrote it.
| Quote: | | You had said that some of your hotstrings use the b0 (no backspace) option. |
It is auto replace.
The application field's work in an overlay mode (type over) as the default. Even if I change it to work as most other applications work (as insert) every time I start it the dam application goes back to overlay. Now I'm just use to it. Anyway, I replaced the backspace with the correct number of left arrows and vola... one happy user.
| Quote: | | Does the above seem like it would be useful? |
I can already do your suggestion with a gosub.
| Code: |
:b0:btw::
GoSub, TestIt
if result = ok
Send, {bs 4}by the way
Return
::otoh::on the other hand
TestIt:
WinGetClass, ActiveClass, A
if ActiveClass in notepad,calculator
result = ok
else
result = no
Return
|
It's not as elegant as your suggestion but you don't need to
change anything to make it work and for the effort it will take you to put it in I don't think it will be worth it.
| Quote: | | Ok. If you ever notice immediately after typing |
I am tracking one right now and once I prove it is not an error in my script, I'll get back to you.  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|