AutoHotkey Community

It is currently May 26th, 2012, 5:01 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: January 29th, 2009, 5:37 pm 
Offline

Joined: January 29th, 2009, 5:27 pm
Posts: 3
Ok, so basically what I want to do is have F1 press "enter" in a game
I own, many times in a row.

I have it "working" in notepad, i've even used setkeydelay to delay it
but it simply doesn't work in the game.

I have looked at the FAQ and it says to try using SendPlay command;
SendMode Play; the hotstring option SP or ControlSend.

The problem is I can't seem to get these working at all, even in notepad.

Here is the code for the basic "Send" which works fine in notepad, but
not in the game.
What I tried with ControlSend follows it.
If anyone could help me put it into format for the four it suggests
trying, I would be very greatful.

Code:
SetKeyDelay, 100
F3::Send {ENTER 50}

I have tried this with a delay of 10, 50, 100, 200, 500, 1000 - nothing.


Code:
SetKeyDelay, 500, 500
F1::ControlSend, , {enter 50}, ahk_class SR2



Any help is appreciated,

Pete


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 29th, 2009, 7:28 pm 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
Ok, you are talking to the right person, here. Some games need a delay during the keypress - In other words,
a delay AFTER the key is DOWN and BEFORE the key is RELEASED. The game I have been working on, seemed to need
a delay of 37 for holding a key down, and a delay of 2 between keypresses. So this should work with sendplay...


Code:
playkeydelay:=37
setkeydelay,,%playkeydelay%,play

F1::
   sendplay {Enter 50}
return




But in my opinion, this is a much better way. I have put it in a function so that it is easy to use for any keypress.
You can experiment with changing the delays, but this is what I found was the fastest without any errors or skips.

Code:
delaybetweenfkeys:=2
fkeydowndelay:=37


F1::
   loop 50
   {
      presskey("Enter")
   }
return

presskey(key,del1 =999999, del2 =999999) ;you cant set variables as default parameters in functions
{                                        ; so this is a way around it
   global delaybetweenfkeys,fkeydowndelay
   del1:=del1=999999 ? fkeydowndelay : del1  ;default value will be value of 'fkeydowndelay'
   del2:=del2=999999 ? delaybetweenfkeys : del2 ;default value will be value of 'delaybetweenfkeys'
   sendinput {%key% down}                ;press the key down
   sleep %del1%                         ;hold for this delay
   sendinput {%key% up}                  ;release key
   sleep %del2%                         ; for this delay
return
}





Even better (depending on what you want) - this will continue pressing enter until you release F1.

Code:
delaybetweenfkeys:=2
fkeydowndelay:=37

F1::
   loop
   {
      if checkkeyreleased(A_thishotkey)   ; a_thishotkey is a built in variable
         break                             ; that stores whatever the last key pressed was
      presskey("Enter")                       ; which of course will be F1
   }
return

presskey(key,del1 =999999, del2 =999999) ;you cant set variables as default parameters in functions
{                                        ; so this is a way around it
   global delaybetweenfkeys,fkeydowndelay
   del1:=del1=999999 ? fkeydowndelay : del1  ;default value will be value of 'fkeydowndelay'
   del2:=del2=999999 ? delaybetweenfkeys : del2 ;default value will be value of 'delaybetweenfkeys'
   sendinput {%key% down}                ;press the key down
   sleep %del1%                         ;hold for this delay
   sendinput {%key% up}                  ;release key
   sleep %del2%                         ; for this delay
return
}


checkkeyreleased(key,checkdelay =2)
{
   
     Sleep, %checkdelay%               ;tiny delay to give computer a chance to see if key is down
   GetKeyState, state, %key%, P         ;stores the state of the key to variable 'state'
   if state = U  ; The key has been released, so break out of the loop.     
       return true
   else
      return false
}



Report this post
Top
 Profile  
Reply with quote  
 Post subject: -
PostPosted: January 30th, 2009, 2:28 am 
Offline

Joined: January 29th, 2009, 5:27 pm
Posts: 3
wow, amazing reply, thanks!

I've just tried all the options you gave me.

Unfortunately none work within the game. :(

All work amazingly in notepad/word etc but nothing in the game.


If anyone sees this, do you know any other hotkey automation program that can do this in games?
There must be something, i've been looking around and i'm finding none :(
The game is new, Saints Row 2, so I guess it uses what people say AHK can't do? So anything that should be able to see in that, would be good.

Thanks for the help mb777! :)

Cheers,

Pete


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2009, 2:37 am 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
have u tried altering the delays in the last example?

try something ridiculous like 200 for both delays, or even 1000


Report this post
Top
 Profile  
Reply with quote  
 Post subject: -
PostPosted: January 30th, 2009, 3:10 am 
Offline

Joined: January 29th, 2009, 5:27 pm
Posts: 3
Yea, i've tried long delays, thats what I t hought it was at first. :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2009, 6:27 am 
Offline

Joined: December 21st, 2008, 7:29 pm
Posts: 181
You could give controlsend a try, not sure if I'll work though.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 11:55 pm 
mb777,

Hi, your script works great for something I'm doing. I just had to play with the keypress and keydelay times.

One question though, is it possible to have this working in conjunction with a permanent keypress?

Something like this...


While F1 is held down, the enter key is pulsing while a thid key (let's say shift) is held down for the duration of F1 being pressed. Basically the equivalent of F1 being remapped to Shift but also pulsing enter.

Thanks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 4:58 am 
holy crap, mb777 you are awesome.. I've been looking for a code like this for hours and couldn't find one until I found your codes.

Thanks alot man


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 5:05 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
pete*, Try using SendMode, Input. It is more reliable than SendPlay.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 5:55 pm 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
Anonymous wrote:
mb777,

Hi, your script works great for something I'm doing. I just had to play with the keypress and keydelay times.

One question though, is it possible to have this working in conjunction with a permanent keypress?

Something like this...


While F1 is held down, the enter key is pulsing while a thid key (let's say shift) is held down for the duration of F1 being pressed. Basically the equivalent of F1 being remapped to Shift but also pulsing enter.

Thanks



You just need 2 extra lines of code:


Code:
delaybetweenfkeys:=2
fkeydowndelay:=37

F1::
   sendinput {Lshift down}     ; when you specify a down keypress, you have to use Left or right modifiers
   loop
   {
      if checkkeyreleased(A_thishotkey)   ; a_thishotkey is a built in variable
         break                             ; that stores whatever the last key pressed was
      presskey("Enter")                       ; which of course will be F1
   }
   sendinput {Lshift up}
return

presskey(key,del1 =999999, del2 =999999) ;you cant set variables as default parameters in functions
{                                        ; so this is a way around it
   global delaybetweenfkeys,fkeydowndelay
   del1:=del1=999999 ? fkeydowndelay : del1  ;default value will be value of 'fkeydowndelay'
   del2:=del2=999999 ? delaybetweenfkeys : del2 ;default value will be value of 'delaybetweenfkeys'
   sendinput {%key% down}                ;press the key down
   sleep %del1%                         ;hold for this delay
   sendinput {%key% up}                  ;release key
   sleep %del2%                         ; for this delay
return
}


checkkeyreleased(key,checkdelay =2)
{
   
     Sleep, %checkdelay%               ;tiny delay to give computer a chance to see if key is down
   GetKeyState, state, %key%, P         ;stores the state of the key to variable 'state'
   if state = U  ; The key has been released, so break out of the loop.     
       return true
   else
      return false
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2009, 12:21 am 
mb777,

Thanks!

Your update works really well.

I just had one more question: Sometimes, but not all the time, when I let go of the F1 key one of the other keys (shift or enter) appears to be 'stuck' like its still being pressed down. Maybe this has to do with the timing of whether or not the enter key is 'down' or not.

Is there anything else that can be added to the code, maybe on F1 up to force it to end the inputs of enter and shift? I was thinking of trying something like on F1 up it suspends and then re-enables the script... maybe that would do it.

If you have any suggestions though that would be great


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2009, 12:38 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Quote:
s there anything else that can be added to the code, maybe on F1 up to force it to end the inputs of enter and shift? I was thinking of trying something like on F1 up it suspends and then re-enables the script... maybe that would do it.
With the last script it should send Enter as long as F1 is held down. Does it not do this for you?

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2009, 2:21 am 
It does send enter when f1 is down, unfortunately when i let go of f1, it doesn't always release enter....

Thanks for the reply


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2009, 3:42 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Code:
F1::
Down := True
Send, {LShift Down}
Loop
{
  Send, {Enter Down}
  Sleep, 37
  Send, {Enter Up}
  If !Down
    Break
}
Send, {LShift Up}
Return

F1 Up::Down := False
This should work.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2009, 3:25 pm 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
Anonymous wrote:
mb777,

Thanks!

Your update works really well.

I just had one more question: Sometimes, but not all the time, when I let go of the F1 key one of the other keys (shift or enter) appears to be 'stuck' like its still being pressed down. Maybe this has to do with the timing of whether or not the enter key is 'down' or not.

Is there anything else that can be added to the code, maybe on F1 up to force it to end the inputs of enter and shift? I was thinking of trying something like on F1 up it suspends and then re-enables the script... maybe that would do it.

If you have any suggestions though that would be great



To be honest, I have had that problem in the application I have written. I thought it was a bug that I had not found yet, or that maybe I was using too short delays, but I have tried other delays and it still happens. I'm not sure why.

Maybe the above example is more reliable


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, SifJar, SKAN and 50 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