AutoHotkey Community

It is currently May 27th, 2012, 7:36 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: September 8th, 2006, 6:50 pm 
Offline

Joined: January 1st, 2006, 6:26 pm
Posts: 55
Unless I'm mistaken, GetKeyState isn't working right.. I'm using this code:

Loop {
Dn:=GetkeyState("RButton","P")
IfEqual,Dn,0, Break
}
Click

I do a right click which is detected by a different script that starts the script with the code above. I keep holding the right button down. But GetkeyState returns 1 as if the button was up, loop terminates and the gui receives a click.

If the shortcut that launches the gui and the loop is in the same script, GetkeyState works fine.

My goal is to press right button down, hold it and choose a button then release the button and get the button pressed. I need to keep the shortcut in a separate script that will choose any of the number of other scripts based on which window is active.

Is there any way to avoid putting this all in one script? Thx..

[edit]: I also tried sending a {RButton down} just before the loop, thinking that should trick ahk into seeing that rbutton is, in fact, physically down. But that didn't work either, it doesn't click right away but it fails to recognize later on that right button is released and end the loop. IOW instead of ending loop before it should, it doesn't end it even after it should.

_________________
-AK


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2006, 2:45 pm 
Offline

Joined: December 30th, 2005, 5:01 pm
Posts: 448
This works OK for me on WinXP SP1:
Code:
Loop {
   Dn:=GetkeyState("RButton","P")
   IfEqual,Dn,1, Break
}
MsgBox, You hold RButton down!
Loop {
   Dn:=GetkeyState("RButton","P")
   IfEqual,Dn,0, Break
}
MsgBox, You keep RButton up again!

Or this too:
Code:
   Hotkey, Rbutton, Rbutton
   Hotkey, Rbutton Up, Rbutton_Up
   F9::ExitApp
Return
Rbutton:
    MsgBox, You hold RButton down!
Return
Rbutton_Up:
   MsgBox, You keep RButton up again!
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2006, 4:01 pm 
Offline

Joined: January 1st, 2006, 6:26 pm
Posts: 55
The way you use it, it works because the right button is pressed while the script is running. That works for me, too. The problem comes up when the button is pressed and held before the script runs; then I run the script, use either of the examples you give and it fires off as if right button was up when in fact it's still down.

Looks like the script waits for the button to be pushed down, then it marks its state as down, and when it receives message that button was released, it sets its state as being up. However, if it's already down when the script starts, it thinks it's up; when you release it, it's either not waiting for the message at all or misinterprets it and does not act as if the button was released. That's the problem I'm having....

One workaround is to have initial button location at a spot where there's no button under it. Then that spot receives that first click and nothing happens. After that when you move the cursor to another key and release the button, it does get the rbutton up message correctly (so I was wrong above..), and clicks.

The problem with this workaround is that it's useful to put default cursor position on top of most used key (for example enter in autocad), then you could do a right click for enter, or you could hold right button and move cursor to another command and then release the button to run it.

I'm afraid I'll have to move all the code for all programs into one script..

_________________
-AK


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2006, 5:40 pm 
Offline

Joined: December 30th, 2005, 5:01 pm
Posts: 448
OK, it seems your script has to work in some weird circumstances :).
I hope this is your situation now. It works on the same (WinXP SP1)
Code:
   AlreadyDown1= Already
   Dn:= GetkeyState("RButton","P")
   If Dn
      Gosub, Rbutton
   Hotkey, Rbutton Up, Rbutton_Up
   Hotkey, Rbutton, Rbutton
   Hotkey, F10, ExitApp
Return
Rbutton:
   If Dn
      Hotkey, Rbutton Up, Rbutton_Up
   MsgBox, % "You hold RButton Down " AlreadyDown%Dn% "!"
   If Dn
      Dn:= false
Return
Rbutton_Up:
   ; If DnWasTrueBefore
   ;   Send, {Rbutton Up}   ; "necessary" if Rbutton was down before script start
   MsgBox, You keep RButton Up Again!
Return
ExitApp:
   ExitApp
Return

It works but some funny things happening after the script has been running. E.g. my browser has unwanted behaviour when rolling the mouse wheel. Solution: There's a Send, {Rbutton Up} somewhere needed, if Rbutton was pressed before the script started. I don't know for your situation whether that Send {Rbutton Up} give some problem?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2006, 11:39 pm 
Offline

Joined: January 1st, 2006, 6:26 pm
Posts: 55
Amazing! it works, at last. And I was almost sure it's impossible. Thanks a ton 8) . I don't really understand how it works though. I will play with it later tonight and I maybe will ask you questions.. thanks!

_________________
-AK


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: sjc1000, SKAN, thor, tomL and 72 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group