Jump to content

loop hotkey file


Go to solution Solved by JockoDundee,

Recommended Posts

While 1
   Sleep(250)
WEnd

;Func---------------------------------------------------------------------------
Global $iTypefunc = 0

HotKeySet("f" , "fPressed")
hotkeyset("u" , "uPressed")
hotkeyset("{enter}" , "enterPressed")

If $iTypefunc = 3 Then
   Sleep(100)
   Send("{SPACE}{DOWN 4}EndFunc{UP 4}")
   $iTypefunc = 0
EndIf

Func fPressed()
   If $iTypefunc = 0 Then
      $iTypefunc += 1
      ToolTip( $iTypefunc )
      Sleep(100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   EndIf
EndFunc

Func uPressed()
   If $iTypefunc = 1 Then
      $iTypefunc += 1
      ToolTip( $iTypefunc )
      Sleep(100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   EndIf
EndFunc

Func enterPressed()
   If $iTypefunc = 2 Then
      $iTypefunc += 1
      ToolTip( $iTypefunc )
      Sleep(100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   EndIf
EndFunc

 ;Func---------------------------------------------------------------------------

 

I'm very very new to autoit and have no idea why this isn't working.

i'm trying to make it so that if i press the buttons "fu" & enter in said order it will activate the send command at the top.

no errors when i run the script, just nothing happens when i press the buttons

Link to comment
Share on other sites

Before you go into the loop, you need to execute your HotKeySet() statements.

Start with this, which should get at least something to happen on keypress, though I’m pretty sure you have some other problems as well…

;Func---------------------------------------------------------------------------
Global $iTypefunc = 0

HotKeySet("f" , "fPressed")
hotkeyset("u" , "uPressed")
hotkeyset("{enter}" , "enterPressed")

While 1
   Sleep(250)
WEnd

If $iTypefunc = 3 Then
   Sleep(100)
   Send("{SPACE}{DOWN 4}EndFunc{UP 4}")
   $iTypefunc = 0
EndIf

Func fPressed()
   If $iTypefunc = 0 Then
      $iTypefunc += 1
      ToolTip( $iTypefunc )
      Sleep(100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   EndIf
EndFunc

Func uPressed()
   If $iTypefunc = 1 Then
      $iTypefunc += 1
      ToolTip( $iTypefunc )
      Sleep(100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   EndIf
EndFunc

Func enterPressed()
   If $iTypefunc = 2 Then
      $iTypefunc += 1
      ToolTip( $iTypefunc )
      Sleep(100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   EndIf
EndFunc

 ;Func---------------------------------------------------------------------------

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

@JockoDundeeOP will never reach the block :

If $iTypefunc = 3 Then
   Sleep(100)
   Send("{SPACE}{DOWN 4}EndFunc{UP 4}")
   $iTypefunc = 0
EndIf

since it is after the infinite while loop.  And there is an EndFunc in the middle of a Send ;)

Link to comment
Share on other sites

I'm quite a newbie when it comes to AutoIt, but I think what you need is this:

Global $iTypefunc = 0

HotKeySet ("f", "fPressed")
HotKeySet ("u", "uPressed")
HotKeySet ("{ENTER}", "enterPressed")

While 1

   If $iTypefunc = 3 Then
      Sleep(100)
      Send("{SPACE}{DOWN 4}EndFunc{UP 4}")
      $iTypefunc = 0
   EndIf

WEnd

Func fPressed()
   If $iTypefunc = 0 Then
      $iTypefunc += 1
      ToolTip ($iTypefunc)
      Sleep (100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   EndIf
EndFunc

Func uPressed()
   If $iTypefunc = 1 Then
      $iTypefunc += 1
      ToolTip ($iTypefunc)
      Sleep (100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   EndIf
EndFunc

Func enterPressed()
   If $iTypefunc = 2 Then
      $iTypefunc += 1
      ToolTip ($iTypefunc)
      Sleep (100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   EndIf
EndFunc

However, it only types "EndFnc" because "u" is a hotkey.  You can maybe solve this by temporarily changing the hotkey definition of "u" at the time that "u" is sent, but a simpler approach may simply be to use the clipboard to insert the text instead of sending the characters individually:

If $iTypefunc = 3 Then
      Sleep(100)
      ClipPut("EndFunc")
      Send("{SPACE}{DOWN 4}^v{UP 4}")
      $iTypefunc = 0
   EndIf

 Samuel

Edited by leuce
Link to comment
Share on other sites

3 hours ago, Nine said:

OP will never reach the block

Yes, I’m aware.  That’s why I said:

5 hours ago, JockoDundee said:

Start with this, which should get at least something to happen on keypress, though I’m pretty sure you have some other problems as well… (Emphasis added)

@mikell

taught me not to lead with the spoon when chopsticks will do :)

3 hours ago, Nine said:

And there is an EndFunc in the middle of a Send 

I assumed it was Debug code, what’s your theory?

Edited by JockoDundee

Code hard, but don’t hard code...

Link to comment
Share on other sites

Hey all! thanks to your tips on some very obvious things i missed while i was sleep deprived i got it to work up to registering the first 2 keypresses, i seem to be having problems with special character keys like {ENTER} and {NUMPAD1} for example, they just don't do anything when pressed, might be a problem with my computer but maybe you guys got some tips?

Link to comment
Share on other sites

 

8 minutes ago, WhaleJesus said:

Hey all! thanks to your tips on some very obvious things i missed while i was sleep deprived i got it to work up to registering the first 2 keypresses, i seem to be having problems with special character keys like {ENTER} and {NUMPAD1} for example, they just don't do anything when pressed, might be a problem with my computer but maybe you guys got some tips?

Nvm it appears i should just write it in lowercase, though now i got the problem that when $iTypefunc = 3  it doesn't seem to trigger the send

Link to comment
Share on other sites

18 minutes ago, WhaleJesus said:

I seem to be having problems with special character keys like {ENTER} and {NUMPAD1} for example, they just don't do anything when pressed.

Well, assuming your code looks similar to what I posted, and assuming you are still running the script, then: pressing ENTER isn't going to appear to do anything because you have defined {ENTER} as a hotkey that runs the enterPressed() function.

So, if you would want to use the ENTER key as you would normally, you would have to disable the hotkey for it, then send it, and then re-enable the hotkey for it again:

Func enterPressed()
   If $iTypefunc = 2 Then
      $iTypefunc += 1
      ToolTip ($iTypefunc)
      Sleep (100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   Else

HotKeySet ("{ENTER}") ; disables the hotkey
Send ("{ENTER}")
HotKeySet ("{ENTER}", "enterPressed") ; enables it again

   EndIf
EndFunc

Samuel

Edited by leuce
Link to comment
Share on other sites

2 minutes ago, leuce said:

Well, assuming your code looks similar to what I posted, and assuming you are still running the script, then: pressing ENTER isn't going to appear to do anything because you have defined {ENTER} as a hotkey that runs the enterPressed() function.

So, if you would want to use the ENTER key as you would normally, you would have to disable the hotkey for it, then send it, and then re-enable the hotkey for it again:

Func enterPressed()
   If $iTypefunc = 2 Then
      $iTypefunc += 1
      ToolTip ($iTypefunc)
      Sleep (100)
   ElseIf $iTypefunc > 0 Then
      $iTypefunc = 0
   Else

HotKeySet ("{ENTER}") ; disables the hotkey
Send ("{ENTER}")
HotKeySet ("{ENTER}", "enterPressed") ; enables it again

   EndIf
EndFunc

Samuel

no no sorry i meant as in enter wasnt triggering $iTypefunc = 3 but my problem was that hotkeyset doesn't register special characters written in all caps so i had to do {enter} instead of {ENTER}

Link to comment
Share on other sites

38 minutes ago, WhaleJesus said:

My problem was that HotKeySet doesn't register special characters written in all caps so I had to do {enter} instead of {ENTER}.

{ENTER} works fine in the version that I posted above.

Link to comment
Share on other sites

HotKeySet("^!+e", "Terminate")

;Func---------------------------------------------------------------------------
Global $iTypefunc = 0
Global $sTitle = " ()"
Global $sEF = "EndFunc"

HotKeySet("f", "fPressed")
HotKeySet("u", "uPressed")
HotKeySet("n", "nPressed")
HotKeySet("c", "cPressed")
HotKeySet("{space}", "spacePressed")
;Func---------------------------------------------------------------------------

While 1
    Sleep(250)
    If $iTypefunc = 5 Then
        ClipPut($sTitle)
        Send("{left 4}{bs}F{right 4}" & $sTitle & "{enter 4}{bs}")
        Send("En{down 2}{enter}{up 4}{left 2}")
        $iTypefunc = 0
    EndIf
WEnd

Func Terminate()
    Exit
EndFunc

Func fPressed()
    ClipPut("f")
    If $iTypefunc = 0 Then
        $iTypefunc += 1
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc > 0 Then
        $iTypefunc = 0
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc = 5 Then
    EndIf

EndFunc   ;==>fPressed

Func uPressed()
    ClipPut("u")
    If $iTypefunc = 1 Then
        $iTypefunc += 1
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc > 0 Then
        $iTypefunc = 0
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc = 5 Then
    EndIf
EndFunc   ;==>uPressed

Func nPressed()
    ClipPut("n")
    If $iTypefunc = 2 Then
        $iTypefunc += 1
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc > 0 Then
        $iTypefunc = 0
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc = 5 Then
    EndIf

EndFunc   ;==>enterPressed

Func cPressed()
    ClipPut("c")
    If $iTypefunc = 3 Then
        $iTypefunc += 1
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc > 0 Then
        $iTypefunc = 0
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc = 5 Then
    EndIf
EndFunc

Func spacePressed()
    ClipPut(" ")
    If $iTypefunc = 4 Then
        $iTypefunc += 1
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc > 0 Then
        $iTypefunc = 0
        ;ToolTip($iTypefunc)
        Send("^v")
    ElseIf $iTypefunc = 5 Then
    EndIf
EndFunc

this works while also allowing you to use the buttons outside of the hotkey, thanks for all the help guys!

Link to comment
Share on other sites

  • Solution

@WhaleJesus, this:

Local $sWord, $sTrigger="Func ", $sComplete="(){Enter 4}End Func{UP 4}{RIGHT 5}"

SetKeys(True)

While Sleep(250)
WEnd

Func Pressed()
   $sWord &= @HotKeyPressed

   SetKeys(False)
   Send(@HotKeyPressed)
   If $sWord = $sTrigger Then
     Send($sComplete)
     $sWord = ""
   ElseIf $sWord <> StringLeft($sTrigger, StringLen($sWord)) Then
     $sWord = ""
   EndIf
   SetKeys(True)
EndFunc

Func SetKeys($bSet)
   For $sKey In StringToAsciiArray($sTrigger)
      If $bSet Then
        HotKeySet(Chr($sKey), Pressed)
      Else
        HotKeySet(Chr($sKey))
      EndIf
   Next
EndFunc

Note: Auto-complete is not worth killing the clipboard.  So that had to go.  Triggers when "Func " are typed in order - even if other letters are in between.  

Code hard, but don’t hard code...

Link to comment
Share on other sites

  • 2 weeks later...
On 7/20/2021 at 3:54 AM, JockoDundee said:

@WhaleJesus, this:

Local $sWord, $sTrigger="Func ", $sComplete="(){Enter 4}End Func{UP 4}{RIGHT 5}"

SetKeys(True)

While Sleep(250)
WEnd

Func Pressed()
   $sWord &= @HotKeyPressed

   SetKeys(False)
   Send(@HotKeyPressed)
   If $sWord = $sTrigger Then
     Send($sComplete)
     $sWord = ""
   ElseIf $sWord <> StringLeft($sTrigger, StringLen($sWord)) Then
     $sWord = ""
   EndIf
   SetKeys(True)
EndFunc

Func SetKeys($bSet)
   For $sKey In StringToAsciiArray($sTrigger)
      If $bSet Then
        HotKeySet(Chr($sKey), Pressed)
      Else
        HotKeySet(Chr($sKey))
      EndIf
   Next
EndFunc

Note: Auto-complete is not worth killing the clipboard.  So that had to go.  Triggers when "Func " are typed in order - even if other letters are in between.  

Thanks!, sorry for the late reply

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...