Autofire and toggle

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Autofire and toggle

Re: Autofire and toggle

Post by Delta Pythagorean » 30 Jan 2018, 13:45

landfillbaby wrote:it turns out it's tied to the physical keyboard's auto-repeat feature, and is interrupted by other keypresses
i used this instead:

Code: [Select all]GeSHi © Codebox Plus

SetKeyDelay -1
t=
Space Up::t=
Space::
t=1
While t {
Send, % " "
Sleep, 250
}
Return
it's basically just the toggle method but without the threading problem


If you want to use a spammer for a key, just use this. It's small, simple, and can be used anywhere in a script, not just a hotkey.

Re: Autofire and toggle

Post by landfillbaby » 28 Jan 2018, 04:21

it turns out it's tied to the physical keyboard's auto-repeat feature, and is interrupted by other keypresses
i used this instead:

Code: [Select all]GeSHi © Codebox Plus

SetKeyDelay -1
t=
Space Up::t=
Space::
t=1
While t {
Send % " "
Sleep 250
}
Return
it's basically just the toggle method but without the threading problem

Re: Autofire and toggle

Post by GreatGazoo » 28 Jan 2018, 02:50

landfillbaby wrote:
GreatGazoo wrote:could it be that the hotkey and the key sent being the same key, that it's creating a loop on it's own
ok, i've just checked, it still works when the input isn't in the outputthis would probably be a bad thing if i wasn't trying to make a loop anyway




yeah i noticed that too with my random number generator, while holding control j it sends random number, enter, and it sends J's too

Code: [Select all]GeSHi © Codebox Plus


^j::
SoundBeep, 525, 100
Random, rand, 1, 10000
send, %rand% {enter}
return

Re: Autofire and toggle

Post by landfillbaby » 28 Jan 2018, 02:06

GreatGazoo wrote:could it be that the hotkey and the key sent being the same key, that it's creating a loop on it's own
ok, i've just checked, it still works when the input isn't in the outputthis would probably be a bad thing if i wasn't trying to make a loop anyway

Re: Autofire and toggle

Post by GreatGazoo » 27 Jan 2018, 19:07

landfillbaby wrote:

Code: [Select all]GeSHi © Codebox Plus

*Space::
Send {Space}
Sleep 250
Return

works for me (holding space presses it exactly 4 times per second), no need for a loop, i guess my keyboard works weird?



could it be that the hotkey and the key sent being the same key, that it's creating a loop on it's own

Re: Autofire and toggle

Post by landfillbaby » 27 Jan 2018, 19:01

Code: [Select all]GeSHi © Codebox Plus

*Space::
Send {Space}
Sleep 250
Return

works for me (holding space presses it exactly 4 times per second), no need for a loop, i guess my keyboard works weird?

Re: Autofire and toggle

Post by tidbit » 05 Mar 2017, 16:22

please read before asking.
Helpful links:
1. Don't know how to use these? READ THIS: https://autohotkey.com/docs/Tutorial.htm
2. AHK not working in your game/program? READ THIS: https://autohotkey.com/boards/viewtopic.php?f=7&t=11084
3. List of keys to use as HOTKEYS (the line with "::"): https://autohotkey.com/docs/KeyList.htm
...


and also a link explaining.
as well as a tutorial teaching you the very basics.

Re: Autofire and toggle

Post by wuuii » 05 Mar 2017, 15:01

ok but how do i change the hotkey

Re: Autofire and toggle

Post by evilC » 30 Jun 2016, 05:30

Please can we remove the GetKeyState technique for detecting release of a key? IMHO it is bad advice (Only works with one key) and is inefficient (Potentially introduces up to 10ms lag if you use a Sleep 10)

See here: https://autohotkey.com/boards/viewtopic.php?f=7&t=19745

Re: Autofire and toggle

Post by Geff T » 09 May 2016, 18:25

tidbit wrote:Welcome to ahk, Geff T :)


ty

i have had to give in and ask a Q here https://autohotkey.com/boards/viewtopic.php?f=18&t=17642&p=85827#p85827but i wont go to OT

Re: Autofire and toggle

Post by tidbit » 09 May 2016, 09:24

Welcome to ahk, Geff T :)

Re: Autofire and toggle

Post by Geff T » 09 May 2016, 06:57

BanarMar wrote:Guys pls help me,
#maxThreadsPerHotkey, 2
setKeyDelay, 50, 50
setMouseDelay, 50
banana:=0

$f1::
; banana:=!banana .... This assigns banana to the value of NOT (!) banana. so lets
; say banana starts out FALSE (0). you then turn banana to NOT FALSE. which is
; TRUE (1). so now banana is set to TRUE. and then lets say you toggle it again.
; you set banana to NOT TRUE, which is FALSE. banana is now set to FALSE.
; .... 1 is true, 0 is false. ! is NOT.
banana:=!banana

while (banana=1)
{
send, hello{space}
sleep, 100
}
return

I want a press f2 to toggle and loop x pls!


change the hotkey FROM $f1:: TO your required F2::
and try reading the help that came with AHK , the search in it is very useful

Re: Autofire and toggle

Post by BanarMar » 09 May 2016, 02:33

Guys pls help me,
#maxThreadsPerHotkey, 2
setKeyDelay, 50, 50
setMouseDelay, 50
banana:=0

$f1::
; banana:=!banana .... This assigns banana to the value of NOT (!) banana. so lets
; say banana starts out FALSE (0). you then turn banana to NOT FALSE. which is
; TRUE (1). so now banana is set to TRUE. and then lets say you toggle it again.
; you set banana to NOT TRUE, which is FALSE. banana is now set to FALSE.
; .... 1 is true, 0 is false. ! is NOT.
banana:=!banana

while (banana=1)
{
send, hello{space}
sleep, 100
}
return

I want a press f2 to toggle and loop x pls!

Re: Autofire and toggle

Post by Geff T » 07 May 2016, 16:22

many thanks for this , example #2 saved the few last grabs of my hair remaining .
i am in the ''gamer wants end result'' demiographic . this was my first go at programming , so it wasnt just that i never knew my if from my gosub , i never knew the diff between AHK and C (and still dont).
i got to the point where i had almot done it without posting for help . i had '' while banana = 1 '' fine . the key issue was that i never had the '' #maxThreadsPerHotkey, 2 '' and was unlikely to find it with a search .

whilst writing another mort apt language for the likes of me is a good idea , it wont stop peeps coming here to ask ''how do i get this AHK to accept a button when i press it , i meen them f keys'' and similar
for the simple fact , when digging a hole , if you have no spade a shovel will do , if you dont know what either is youll stay using your hands or find a sharpened stick .

Re: Autofire and toggle

Post by evilC » 09 Mar 2016, 14:52

Because the AHK documentation very clearly says what P does.
https://autohotkey.com/docs/commands/GetKeyState.htm

It makes GetKeyState differentiate between the Physical state of the keyboard and the Logical state.

Re: Autofire and toggle

Post by Stain Blapelton » 09 Mar 2016, 12:08

Hello. I see the code "If (GetKeyState("LButton","P"))" just about everywhere when looking up rapid-fire scripts, but nobody ever explains what it means. Does the comma between quoted inputs "LButton" and "P" mean "or" or "and"? Where did the "P" come into your script, anyhow? What would this expression look like if it just checked whether, say, the "z" key is currently pressed?

Re: Autofire and toggle

Post by Hannik » 03 Mar 2016, 07:10

Thanks so much..that worked..

Hannik

Re: Autofire and toggle

Post by evilC » 03 Mar 2016, 06:06

oops, typo.

macro_on := !macro on should read macro_on := !macro_on

I corrected my original code

Re: Autofire and toggle

Post by Hannik » 03 Mar 2016, 02:23

Thanks for all your help but I seem to have the same problem with this one that had with others..I press the button to stop it..and it just keeps going..so its not toggling off...no idea why.

Hannik

Re: Autofire and toggle

Post by joedf » 03 Mar 2016, 01:38

Very nice ;)

Top