AutoHotkey Community

It is currently May 26th, 2012, 6:13 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Msg box too slow
PostPosted: February 25th, 2008, 7:20 am 
Offline

Joined: February 22nd, 2008, 6:12 pm
Posts: 44
Hi, when im testing this code to say Ctrl² whenever i press Ctrl 2 times withing 400 miliseconds but i feel the Msg Box takes too long to show up. I'ld it to show as soon as i hit Ctrl for the second time

Do you guys have any clue? All i could find was this post by Oberon
http://www.autohotkey.com/forum/viewtopic.php?t=28922&highlight=slow+msgbox
Code:
~*LControl::
if ctrl_press > 0          
{
    ctrl_press += 1
    return
}
ctrl_press = 1
SetTimer, ctrl2, 400
return

ctrl2:
{
SetTimer, ctrl2, off
if ctrl_press = 2
MsgBox, Ctrl²
}
ctrl_press = 0
return


- TY :)

_________________
- Humor is but another weapon against the universe - Mel Brooks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 8:02 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Code:
~LControl::
If ( A_TimeSincePriorHotkey > 0 AND A_TimeSincePriorHotkey < 400 )
    SetTimer, MyRoutine, -1
Return

MyRoutine:
 MsgBox Ctrl²
Return


:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 9:36 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
This is better / reliable version:

Code:
~LControl::
 Loop
   If ! GetKeyState( "LControl","P" )
      Break

 TC := A_TickCount
 Loop  {
         If GetKeyState( "LControl","P" )
          {
            SetTimer, MyRoutine, -1
            Break
          }
         If ( A_TickCount - TC  > 400 )
           Break
       }
Return

MyRoutine:
 MsgBox Ctrl²
Return


:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 11:19 am 
SKAN wrote:
This is better / reliable version...

...:eek:...how about this?...

Code:
~Ctrl up::
Ctrl_TS:=A_TimeSincePriorHotkey
if (Ctrl_TS>=19 && Ctrl_TS<=319) {
   ;//msgbox, 64, , Ctrl_TS(%Ctrl_TS%)
   ;//SetTimer, CtrlDoubleRelease, 19
   Gosub, CtrlDoubleRelease
} else if (Ctrl_TS>=19 && Ctrl_TS<=1019) {
   ;//Just comment this out when done testing...
   msgbox, 16, , Too Slow: Ctrl_TS(%Ctrl_TS%)
}
return

CtrlDoubleRelease:
;//SetTimer, CtrlDoubleRelease, Off
msgbox, 64, , Ctrl²(%Ctrl_TS%)
return

...lol...try it 10 times & post your most frequent successful double release times...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 4:02 pm 
Offline

Joined: February 18th, 2008, 8:26 pm
Posts: 442
I don't understand, why do you need a SetTimer?

Code:
~*LControl::
If (A_ThisHotkey == A_PriorHotkey and A_TimeSincePriorHotkey < 400)
   MsgBox, Ctrl²
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 9:29 pm 
Offline

Joined: February 22nd, 2008, 6:12 pm
Posts: 44
SetTimer came out of my ignorance, saw that code somewhere else and thought it would accomplish what i wanted. I like the 4 lines code best tho :wink:

- TY

Oberon, the King of the fairies! :D

_________________
- Humor is but another weapon against the universe - Mel Brooks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 9:56 pm 
Offline

Joined: February 22nd, 2008, 6:12 pm
Posts: 44
It triggers of if i keep Ctrl pressed for more than 400 ms.

How would i stop that from happening?

- TY

_________________
- Humor is but another weapon against the universe - Mel Brooks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 10:17 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
bvaroni wrote:
It triggers of if i keep Ctrl pressed for more than 400 ms.


Borrowing ideas - It could be one the following :

Code:
~*LControl::
Loop
   If ! GetKeyState( "LControl","P" )
      Break

     
 If ( A_ThisHotkey == A_PriorHotkey and A_TimeSincePriorHotkey < 400 )
    MsgBox, Ctrl²
Return


Code:
~*LControl Up::
 If ( A_ThisHotkey == A_PriorHotkey and A_TimeSincePriorHotkey < 400 )
    MsgBox, Ctrl²
Return


:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2008, 5:15 am 
Offline

Joined: February 22nd, 2008, 6:12 pm
Posts: 44
Code:
~*LControl Up::
 If ( A_ThisHotkey == A_PriorHotkey and A_TimeSincePriorHotkey < 400 )
    MsgBox, Ctrl²
Return
Works perfectly, so clever!

I tested both codes and u need to release Ctrl key to activate msg, is there an alternative that activates when Ctrl is pressed for second time?

I really appreciate ur patience,

Thanks alot!

_________________
- Humor is but another weapon against the universe - Mel Brooks


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, JSLover, Tipsy3000 and 69 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