WhaleJesus Posted July 19, 2021 Share Posted July 19, 2021 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 More sharing options...
JockoDundee Posted July 19, 2021 Share Posted July 19, 2021 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… expandcollapse popup;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 More sharing options...
Nine Posted July 19, 2021 Share Posted July 19, 2021 @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 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
leuce Posted July 19, 2021 Share Posted July 19, 2021 (edited) I'm quite a newbie when it comes to AutoIt, but I think what you need is this: expandcollapse popupGlobal $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 July 19, 2021 by leuce Link to comment Share on other sites More sharing options...
JockoDundee Posted July 19, 2021 Share Posted July 19, 2021 (edited) 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 July 19, 2021 by JockoDundee Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
leuce Posted July 19, 2021 Share Posted July 19, 2021 5 minutes ago, JockoDundee said: I assumed it was Debug code, what’s your theory? I assumed that he wanted the script to literally type "E-n-d-F-u-n-c". Link to comment Share on other sites More sharing options...
WhaleJesus Posted July 19, 2021 Author Share Posted July 19, 2021 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 More sharing options...
WhaleJesus Posted July 19, 2021 Author Share Posted July 19, 2021 Just now, leuce said: I assumed that he wanted the script to literally type "E-n-d-F-u-n-c". yeah i just wanted a quick autocomplete for making a func the same way you go #Variable & {tab} in brackets Link to comment Share on other sites More sharing options...
WhaleJesus Posted July 19, 2021 Author Share Posted July 19, 2021 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 More sharing options...
leuce Posted July 19, 2021 Share Posted July 19, 2021 (edited) 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 July 19, 2021 by leuce Link to comment Share on other sites More sharing options...
WhaleJesus Posted July 19, 2021 Author Share Posted July 19, 2021 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 More sharing options...
leuce Posted July 19, 2021 Share Posted July 19, 2021 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 More sharing options...
WhaleJesus Posted July 19, 2021 Author Share Posted July 19, 2021 expandcollapse popupHotKeySet("^!+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 More sharing options...
JockoDundee Posted July 19, 2021 Share Posted July 19, 2021 Sorry @WhaleJesus, I don't think this works, at least in notepad. Among other things, you don't ever use the $sEF variable, so how does it print "EndFunc". Also, the keys get messed up. Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Solution JockoDundee Posted July 20, 2021 Solution Share Posted July 20, 2021 @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 More sharing options...
WhaleJesus Posted July 29, 2021 Author Share Posted July 29, 2021 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now