AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Keys sticking

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Tue Jun 01, 2004 10:10 pm    Post subject: Keys sticking Reply with quote

Hi, I'm having problems with keys sticking again. With this script the windows key sticks but which ever key I use as a hotkey will stick e.g. control or alt.

On one computer it will stick almost every time and on the other it will stick every other time. Both computers run windows XP.

It is the script below that is causing the trouble-

Code:

#n::
winactivate
clipboard=
send, ^c
ifnotexist, Untitled
{
run, notepad.exe
}
winwait, Untitled
ControlSend, Edit1, %clipboard%, Untitled 


When I run that script with #n and then press "r" for example then the run window will appear (because the windows key is stuck).

What the script does is to copy a line of text from internet explorer into notepad.

Thanks, Acsell
Back to top
View user's profile Send private message Send e-mail
beardboy



Joined: 02 Mar 2004
Posts: 444
Location: SLC, Utah

PostPosted: Wed Jun 02, 2004 1:40 am    Post subject: Reply with quote

I tested with this slightly modified script and had the same problem on windows 2000, AHK 1.0.12.

Code:
#n::
;winactivate
clipboard=
send, ^c
SetTitlematchmode, 2
ifnotexist, new file
{
  run, notepad.exe
}
winwait, new file
ControlSend, RichEdit20A1, %clipboard%, new file
return


thanks,
beardboy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
beardboy



Joined: 02 Mar 2004
Posts: 444
Location: SLC, Utah

PostPosted: Wed Jun 02, 2004 1:57 am    Post subject: Reply with quote

Ran the same script with AHK 1.0.11 and the keys did not stick.

thanks,
beardboy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Wed Jun 02, 2004 2:40 am    Post subject: Reply with quote

Beardboy, I think it's a coincidence that they didn't stick in 1.0.12 because I can reproduce this on my XP machine even with 1.0.12.

To the original poster: First just a brief observation that you probably meant to use IfWinNotExist here:
ifnotexist, Untitled

Now the explanation:
This is a known limitation whenever the keyboard hook isn't installed. To workaround it, try any one of the following:

- Use the following in place of ControlSend:
Control, EditPaste, %clipboard%`r`n, Edit1, Untitled

- Reduce delays at the top of the script, or inside this hotkey subroutine, as follows:
SetKeyDelay, 0
SetWinDelay, 10

- Specify the line #InstallKeybdHook anywhere in the script.

Only one of the above should be needed to resolve this.

Explanation for this limitation: When the keyboard hook is not installed, the program does not know which keys the user is physically holding down so must make a best guess. So, if the send occurs after #HotkeyModifierTimeout has expired (due to WinDelay and KeyDelay in this case), the program assumes that any modifiers in a down state are that way intentionally and not as part of the hotkey. Such modifiers therefore become part of the persistent modifiers which the Send command insists be down for all letters being sent. But if modifier really is part of the hotkey (LWin or RWin in this case) and the user releases it during the send, the program will push the key back down again to enforce the fact that the key should be down for the entire send.

There may be a way to improve this behavior in the future, but it's a very tricky thing to do without the keyboard hook. The hook makes AHK nearly omniscient so virtually all keyboard problems like this disappear completely.


Last edited by Chris on Wed Jun 02, 2004 2:45 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
beardboy



Joined: 02 Mar 2004
Posts: 444
Location: SLC, Utah

PostPosted: Wed Jun 02, 2004 2:44 am    Post subject: Reply with quote

Quote:
Beardboy, I think it's a coincidence that they didn't stick in 1.0.12 because I can reproduce this on my XP machine even with 1.0.12.

I must have been quick on the draw with 1.0.11. Wink
Retested and held the windows key down a little longer, and the same problem does occur.

thanks,
beardboy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
jamestr



Joined: 05 Apr 2004
Posts: 96
Location: Connecticut USA

PostPosted: Wed Jun 02, 2004 3:13 pm    Post subject: Reply with quote

If i select some text in notepad instance 1(to send to notepad instance 2), and then 'hold down' the hotkey, the hotkey suffix 'q' will sometimes showup in notepad 1, or notepad 1 will receive a ctrl q, and open up the quick open dialog.

I realize that 'control editpaste' is the proper way to do this.


Code:

#InstallKeybdHook
+q::

clipboard =
send, ^c
clipwait, .5
ifwinnotexist, Untitled
{
run, notepad.exe
}
   ;IfWinExist, Untitled - Notepad
   ;   WinActivate  ; Automatically uses the window found above.
   ;winwait, Untitled
   ;control, EditPaste, %clipboard%`r`n, Edit1, Untitled
ControlSend, Edit1, %clipboard%`n
sleep 250

return
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Wed Jun 02, 2004 6:48 pm    Post subject: Reply with quote

Does that happen with v1.0.12 or some earlier version? I made some changes in the original release v1.0.12 that might help, and for v1.0.13 I'm planning another improvement that was inspired by the contributors to this topic.
Back to top
View user's profile Send private message Send e-mail
jamestr



Joined: 05 Apr 2004
Posts: 96
Location: Connecticut USA

PostPosted: Thu Jun 03, 2004 12:15 am    Post subject: Reply with quote

thats with XP and 1.0.12

also

the processing of the code below has changed with 1.0.12.

with v1.0.12 when i release the a & xbutton1 keys, ahk sends an undesired 'a', which it did not do with the earlier releases.

key history shows both mouse and keyboard hooks are running.

Code:
$a::send, a                            
;;;;$^a::send, ^a

a & xbutton1::
Loop
{
GetKeyState, state, xbutton1, P
    if state = u
    {
    break
    }
send, {bs}
}
return
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Thu Jun 03, 2004 1:13 am    Post subject: Reply with quote

Darn, sorry about that. I applied a fix to the installer that you can re-download if you want:

http://www.autohotkey.com/download/

Fixed hook hotkeys that used a keyboard prefix but a mouse button suffix when the prefix was also a suffix as in this example, which was broken in v1.0.12 [thanks jamestr]:
$a::send, a
a & lbutton::
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Thu Jun 03, 2004 2:17 am    Post subject: Reply with quote

Quote:
If i select some text in notepad instance 1(to send to notepad instance 2), and then 'hold down' the hotkey, the hotkey suffix 'q' will sometimes showup in notepad 1, or notepad 1 will receive a ctrl q, and open up the quick open dialog. I realize that 'control editpaste' is the proper way to do this.

I tried it and I get that too. The problem lies is the fact that ControlSend changes the logical state of the modfier keys to improve reliability. But during the times when the state has been altered, sometimes a repeated keystroke comes in and the system sees it with the wrong modifiers, so a registered hotkey fires automatically.

I did discover that it might be better to use {Enter} rather than `r or `n, since it seems that the latter involve the use of the Control key. So this makes things slight more reliable:
ControlSend, Edit1, %clipboard%{enter}

And reducing KeyDelay to 0 alleviates a lot of problems, including this one.

Thanks for your testing and insight. Based on this example, I think I see a way that might be used to reduce the Send command's interference with the key-repeat feature.
Back to top
View user's profile Send private message Send e-mail
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Sat Jun 05, 2004 4:27 pm    Post subject: Reply with quote

Thanks, that seems to have fixed it. It also copies into notepad alot faster now.

Thanks, Jon
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group