AutoHotkey Community

It is currently May 27th, 2012, 11:43 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: May 25th, 2010, 8:53 pm 
Offline

Joined: June 22nd, 2006, 8:36 pm
Posts: 27
I tried to remap a single key to 3 others. (For a virtual onscreen piano in my case)
So instead of:
1::A
I need it to be for example:
1::A+B+C
But it needs to act the same way, not just send the keystrokes.
I tried a loop with getkeystate, but I know that what I did must be wrong:
Code:
1::
loop
{
getkeystate, num1, 1
if num1 = U
   break
send {A down}{B down}{C down}
keywait 1
}
send {A up}{B up}{C up}
return


It does work for what I need it to do, but it's not acceptable the way it works. Firstly it doesn't repeat the key and if I have another remap 2::D+E+F and press it while the other loop runs, the first loop won't break before releasing the second key.

I know I must be going the wrong way.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2010, 9:03 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
Try this it holds the key for the duration you hold 1
Code:
1::
Send {a Down}{b Down}{c Down}
KeyWait 1
Send {a Up}{b Up}{c Up}
Return

Or this if you need the multiple down events of holding a key
Code:
1::Send {a Down}{b Down}{c Down}
1 Up::Send {a Up}{b Up}{c Up}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2010, 9:22 pm 
Offline

Joined: June 22nd, 2006, 8:36 pm
Posts: 27
I didn't know you could do that "2 up::etc"
The first code works perfectly for what I need.
It doesn't repeat the keys, but I don't need it.

The second one also works but if I hold it too long it lags a bit, sends too much.

Thanks a lot.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2010, 9:31 pm 
Offline

Joined: June 22nd, 2006, 8:36 pm
Posts: 27
But still there must be a better way to do it.
It does the same problem as my earlier attempt. I can't press them at the same time with other remappings.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2010, 9:44 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
Getting rid of the keywaits can get a little complicated :D
Code:
var1=0
var2=0
1::
if var1
 return
var1=1
Send {a Down}{b Down}{c Down}
SetTimer ,WaitForOne, 10
Return

2::
if var2
 return
var2=1
Send {d Down}{e Down}{f Down}
SetTimer ,WaitForTwo, 10
Return

WaitForOne:
If GetKeyState("1")
 Return
SetTimer ,WaitForOne, Off
var1=0
Send {a Up}{b Up}{c Up}
Return

WaitForTwo:
If GetKeyState("2")
 Return
SetTimer ,WaitForTwo, Off
var2=0
Send {d Up}{e Up}{f Up}
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2010, 9:55 pm 
Offline

Joined: June 22nd, 2006, 8:36 pm
Posts: 27
Very interesting, thank you for your time.
This also works, but I didn't tell you everything, I never imagined it would be so complex.
Here's what I did:
Code:
var1=0
var2=0
var3=0
1::
if var1
 return
var1=1
Send {j Down}{; Down}{r Down}
SetTimer ,WaitForOne, 10
Return

2::
if var2
 return
var2=1
Send {j Down}{; Down}{t Down}
SetTimer ,WaitForTwo, 10
Return

3::
if var3
 return
var3=1
Send {h Down}{, Down}{; Down}
SetTimer ,WaitForThree, 10
Return

WaitForOne:
If GetKeyState("1")
 Return
SetTimer ,WaitForOne, Off
var1=0
Send {j Up}{; Up}{r Up}
Return

WaitForTwo:
If GetKeyState("2")
 Return
SetTimer ,WaitForTwo, Off
var2=0
Send {j Up}{; Up}{t Up}
Return

WaitForThree:
If GetKeyState("3")
 Return
SetTimer ,WaitForThree, Off
var3=0
Send {h Up}{, Up}{; Up}
Return

Now if I press 1 and 2, and release 2, it also releases some of the keys that 1 is supposed to do and so on. The keys don't repeat themselves when held also. (Not a problem in my case, but I'm very curious as to how to make this work)
And the code you provided, the does the same effects as the first one you posted. :/
I'm still messing around here.
How can A::B be so tough to replicate with multiple binds hehe.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2010, 10:06 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
T-nm wrote:
How can A::B be so tough to replicate with multiple binds hehe.
Because A::B is more complicated than you think it is.
Remapping Keys and Buttons wrote:
When a script is launched, each remapping is translated into a pair of hotkeys. For example, a script containing a::b actually contains the following two hotkeys instead:

*a::
SetKeyDelay -1 ; If the destination key is a mouse button, SetMouseDelay is used instead.
Send {Blind}{b DownTemp} ; DownTemp is like Down except that other Send commands in the script won't assume "b" should stay down during their Send.
return

*a up::
SetKeyDelay -1 ; See note below for why press-duration is not specified with either of these SetKeyDelays.
Send {Blind}{b Up}
return

You might try
Code:
1::
Send {a Down}{b Down}{c Down}
Sleep 50 ;to slow repeat rate
Return
1 Up::Send {a Up}{b Up}{c Up}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2010, 10:15 pm 
Offline

Joined: June 22nd, 2006, 8:36 pm
Posts: 27
I see. With sleep 10 it works, in a way.
I'll continue messing a bit with this.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2010, 10:20 pm 
Offline

Joined: June 22nd, 2006, 8:36 pm
Posts: 27
Well here's what I did lol:
Code:
*1::
SetKeyDelay -1
Send {Blind}{j DownTemp}{; DownTemp}{r DownTemp}
return

*1 up::
SetKeyDelay -1
Send {Blind}{j Up}{; up}{r up}
return

*2::
SetKeyDelay -1
Send {Blind}{j DownTemp}{; DownTemp}{t DownTemp}
return

*2 up::
SetKeyDelay -1
Send {Blind}{j Up}{; up}{t up}
return

*3::
SetKeyDelay -1
Send {Blind}{h DownTemp}{, DownTemp}{; DownTemp}
return

*3 up::
SetKeyDelay -1
Send {Blind}{h Up}{, up}{; up}
return


Seems to be cleaner, faster and simpler. Still can't get the keys to stick down if upped by another remap.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2010, 1:25 am 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
You could try something like this to control what comes up based on what is down :)
Code:
1::
Send {j Down}{; Down}{r Down}
return

*2::
Send {j Down}{; Down}{t Down}
return

*3::
Send {h Down}{, Down}{; Down}
return

*1 up::
*2 up::
*3 up::
State1:=GetKeyState("1")
State2:=GetKeyState("2")
State3:=GetKeyState("3")
If !State1 and !State2 and !State3 ;if all three keys are up then all sent keys come up
  Send {h Up}{, up}{; up}{j Up}{r Up}{t Up}
If State1 and !State2 and !State3 ;if only 1 is down all keys not in one come up
  Send {h Up}{, up}{t Up}
If !State1 and State2 and !State3
  Send {h Up}{, up}{r Up}
If State1 and State2 and !State3
  Send {h Up}{, up}
If !State1 and !State2 and State3
  Send {j Up}{r Up}{t Up}
If State1 and !State2 and State3
  Send {t Up}
If !State1 and State2 and State3
  Send {r Up}
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2010, 1:55 am 
Offline

Joined: June 22nd, 2006, 8:36 pm
Posts: 27
Yes indeed.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], MSN [Bot] and 19 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