Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

F1 as a hotkey


  • Please log in to reply
5 replies to this topic
NickTown
  • Members
  • 4 posts
  • Last active: Oct 29 2012 04:48 PM
  • Joined: 29 Oct 2012
I'm trying to write a script to repeatedly press F1 every 20msec for World or Warcraft.

Here is what I have and I'm not sure why it isn't working.

$F1::
loop
{
  GetKeyState, ScrollLockState, ScrollLock, T

  if (ScrollLockState = "U") {
	break
  } else {
	Send $F1
	Sleep, 10 ; Sleep for 20 msec
	GetKeyState, state, $F1, P
	if state = U  ; The key has been released, so break out of the loop.
	  break
  }
}
return

any help is appreciated.

~Nick

vsub
  • Members
  • 1098 posts
  • Last active: Sep 28 2015 09:48 AM
  • Joined: 10 Nov 2011
Umm you have couple of errors in your code but first,how do you want to code to work?
While holding F1 to repeatedly send F1 or just press it once and start sending F1 every 20 seconds.

The GetKeyState condition of F1 is useless because Send {F1) send down and up state so the GetKeyState will always break the loop

NickTown
  • Members
  • 4 posts
  • Last active: Oct 29 2012 04:48 PM
  • Joined: 29 Oct 2012

Umm you have couple of errors in your code but first,how do you want to code to work?
While holding F1 to repeatedly send F1 or just press it once and start sending F1 every 20 seconds.

The GetKeyState condition of F1 is useless because Send {F1) send down and up state so the GetKeyState will always break the loop


While holding down F1 I want it to act like its being pressed repeatedly every .2 seconds.

So should I take out GetKeyState?

vsub
  • Members
  • 1098 posts
  • Last active: Sep 28 2015 09:48 AM
  • Joined: 10 Nov 2011
$F1::

loop

{

  GetKeyState, ScrollLockState, ScrollLock, T



  if (ScrollLockState = "U") {

	break

  } else {

	Send {F1}

	Sleep, 20 ; Sleep for 20 msec

	GetKeyState, state, F1, P

	if state = U  ; The key has been released, so break out of the loop.

	  Break

  }

}

return


NickTown
  • Members
  • 4 posts
  • Last active: Oct 29 2012 04:48 PM
  • Joined: 29 Oct 2012

$F1::
loop
{
  GetKeyState, ScrollLockState, ScrollLock, T

  if (ScrollLockState = "U") {
	break
  } else {
	Send {F1}
	Sleep, 20 ; Sleep for 20 msec
	GetKeyState, state, F1, P
	if state = U  ; The key has been released, so break out of the loop.
	  Break
  }
}
return






That works perfectly, thanks for your help.

dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
This is another way to make key repeatedly send itself while held:
#usehook ;*1

hotkey, f1, spam ;*2

return

spam: ;*3

{

   while getkeystate(a_thishotkey, "p") ;*4

    {

	  sleep, 20 ;*5

	  sendinput, {%a_thishotkey%} ;*6

    }

}

return



end::exitapp ;*7



/*

1 Directs subsequent hotkeys to use the keyboard hook.

2 Uses Hotkey Command to create a f1 button hotkey tied to the spam subroutine.

3 Spam subroutine label. When called, any code below it will run.

4 While loop and getkeystate, will loop as long as the originating hotkey is held.

5 20ms sleep between loops.

6 Each loop run sends whichever hotkey originated the subroutine.

7 Emergency shutdown.

*/
This code can be expanded by adding other hotkey command at thet top. The same subroutine will work for any number of keys ( provided they are pressed one at a time).
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact