AutoHotkey Community

It is currently May 26th, 2012, 4:35 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Sequence of keys
PostPosted: March 15th, 2008, 8:54 pm 
Offline

Joined: March 15th, 2008, 8:42 pm
Posts: 2
Hello !

I need some help with building a script that will be executed on a sequence of keys pressed, ie:

Win+c (press and release) + t : that will execute one program with a certain configuration

Win+c (press and release) + h : that will execute the some program but with a diferent configuration.

I didsomething like this:

Code:
#c::
keywait,t,D
Run C:\telindus\programas\cygwin\cygwin_telindus.bat
keywait,h,D
Run C:\telindus\programas\cygwin\cygwin.bat
return


but it doesn't work very well.
Can anyone help me ?

Thanks in advance

Hugo Marcelino


Report this post
Top
 Profile  
Reply with quote  
 Post subject: A possible solution
PostPosted: March 15th, 2008, 10:23 pm 
Offline

Joined: March 15th, 2008, 9:11 pm
Posts: 8
Location: Behind You
I've seen two problems with this script

Firstly, if you do not press either t or h directly after pressing Win+C, and you happen to type the letter t (or h) in somewhere else (eg : the autohotkey forum), it will activate then?.
Secondly, if I am correct, then it will never respond to h, unless it has already picked up t.

Is this what you meant by it not working very well?

If so, then try this (it is a bit inefficient though)
Code:
#SingleInstance
#Persistent

winc_pressed = 0

#c::
winc_pressed = 1
SetTimer, ResetWinC, -3000
Return

ResetWinC:
winc_pressed = 0
Return

~t::
IfEqual, winc_pressed, 1
{
   Run, C:\telindus\programas\cygwin\cygwin_telindus.bat
   winc_pressed = 0
}
Return

~h::
IfEqual, winc_pressed, 1
{
   Run, C:\telindus\programas\cygwin\cygwin.bat
   winc_pressed = 0
}
Return


If not, then sorry, but I can't help you.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 7:24 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Here's my solution:
Code:
#c::
    Hotkey, t, #c_key, On
    Hotkey, h, #c_key, On
    SetTimer, #c_timeout, -500 ; Tweak this.
return

#c_timeout:
    Hotkey, t, Off
    Hotkey, h, Off
return

#c_key:
    gosub #c_timeout
    MsgBox %A_ThisHotkey%
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 7:52 am 
Offline

Joined: July 21st, 2006, 12:26 am
Posts: 223
[Note from moderator: Quoting the post directly above is unnecessary and inconvenient to readers. Quote removed.]

nice, using Lexikos' code:

Code:
LWin & c::
   send {LWin}c
   keywait, LWin
   keywait, c
   hotkey, t, tkey, On
   hotkey, h, hkey, On
   settimer, turnoff, 500
return

turnoff:
   hotkey, t, off
   hotkey, h, off
return

tkey:
   Run C:\telindus\programas\cygwin\cygwin_telindus.bat
return
   
hkey:
   Run C:\telindus\programas\cygwin\cygwin.bat
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 8:58 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
For me, #c (Win+c) and LWin & c are identical, since I have no RWin key.

Why send LWin and c individually, or at all?
Code:
send {LWin}c  ; presses and releases LWin, then presses and releases c.
send #c  ; holds win, presses and releases c, releases win.
~#c::  ; detects Win + C without blocking either.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 12:38 pm 
Offline

Joined: May 30th, 2006, 11:47 am
Posts: 49
I have been trying the Input method in some scripts. How is this?
Code:
#c::
  MatchList = h,t
  Input, UserInput, L1 C T3,, %MatchList%
  SetKeyDelay, -1
  If UserInput = h
    Run C:\telindus\programas\cygwin\cygwin.bat
  else if UserInput = t
    Run C:\telindus\programas\cygwin\cygwin_telindus.bat
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2008, 4:15 am 
Offline

Joined: July 21st, 2006, 12:26 am
Posts: 223
Lexikos wrote:
For me, #c (Win+c) and LWin & c are identical, since I have no RWin key.

Why send LWin and c individually, or at all?
Code:
send {LWin}c  ; presses and releases LWin, then presses and releases c.
send #c  ; holds win, presses and releases c, releases win.
~#c::  ; detects Win + C without blocking either.


hmm i see now the difference and i think your method is safer, so {LWin}c should be changed by #c so keywait can be discarted.

thank you again Lexikos


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2008, 3:47 pm 
Offline

Joined: March 15th, 2008, 8:42 pm
Posts: 2
sorry.

I've bean away and only today i could see the responses.

And i'm very happy, because that was exactly what i wanted

Thanks for your help.

Best Regards


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot] and 12 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