Dxnny Posted November 25, 2019 Share Posted November 25, 2019 I'm currently running a script so when I press F it will do something, then G will do something else, is there a way to make it so that when I press a button it will pause this part of the code and allow me to use those some hotkeys (F, G, etc) for a different part of code? Link to comment Share on other sites More sharing options...
SkysLastChance Posted November 25, 2019 Share Posted November 25, 2019 What have you tried? You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott Link to comment Share on other sites More sharing options...
Dxnny Posted November 25, 2019 Author Share Posted November 25, 2019 1 minute ago, SkysLastChance said: What have you tried? I tried pausing a section of the script, and resuming a different part, didn't work, not sure if that's possible but I may have been doing it wrong. Link to comment Share on other sites More sharing options...
Qwerty212 Posted November 25, 2019 Share Posted November 25, 2019 12 minutes ago, Dxnny said: I tried pausing a section of the script, and resuming a different part, didn't work, not sure if that's possible but I may have been doing it wrong. I think that SkysLastChance was meaning if you can provide some code to check it. SkysLastChance 1 Link to comment Share on other sites More sharing options...
Dxnny Posted November 25, 2019 Author Share Posted November 25, 2019 expandcollapse popup#include <Misc.au3> $dll = DllOpen("user32.dll") Global $Paused HotKeySet("{NUMPADSUB}", "TogglePause") HotKeySet("{NUMPADENTER}", "Terminate") While 1 Sleep ( 50 ) ; Actions 1 If _IsPressed("46", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 252, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("47", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 348, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("48", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 444, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("4A", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 540, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("4B", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 814, 513, 1 ) Sleep (100) Send ("I") EndIf ; Actions 2 If _IsPressed("4C", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 728, 252, 736, 684, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("BA", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 728, 348, 736, 684, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("BC", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 728, 444, 736, 684, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("BE", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 728, 540, 736, 684, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("BF", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 814, 513, 736, 684, 1 ) Sleep (100) Send ("I") EndIf WEnd DllClose($dll) Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) WEnd EndFunc Func Terminate() Exit 0 EndFunc This is the code I have right now, very messy, I'm trying to figure out a way so when I press a button, Actions 1 section pauses, and Actions 2 category becomes active, that way I can have the same hotkeys for both categories without them messing up each other, I hate having all these buttons for different actions, rather just keep it to 5. Link to comment Share on other sites More sharing options...
SkysLastChance Posted November 25, 2019 Share Posted November 25, 2019 expandcollapse popup#include <Misc.au3> HotKeySet(("{ESC}"),"Terminate") HotKeySet(("{f}"),"Notepad") ConsoleWrite("'f' key will now open notepad" & @CRLF) ConsoleWrite("'a' to switch hotkey" & @CRLF) ConsoleWrite("'esc' to stop script" & @CRLF) Local $vhotkey = 0 While Sleep (100) If _IsPressed("41") AND $vhotkey = 0 Then ;41 = a ConsoleWrite("'f' key will now open calulator" & @CRLF) HotKeySet(("{f}"),"Calc") $vhotkey = 1 ElseIf _IsPressed("41") AND $vhotkey = 1 Then ;41 = a ConsoleWrite("'f' key will now open notepad" & @CRLF) HotKeySet(("{f}"),"Notepad") $vhotkey = 0 EndIf WEnd Func Notepad() Run("notepad.exe") EndFunc Func Calc() Run("calc.exe") EndFunc Func Terminate() Exit EndFunc You could try something like this. Change notepad and calc to a msgbox if you need to test. You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott Link to comment Share on other sites More sharing options...
Dxnny Posted November 25, 2019 Author Share Posted November 25, 2019 2 minutes ago, SkysLastChance said: expandcollapse popup#include <Misc.au3> HotKeySet(("{ESC}"),"Terminate") HotKeySet(("{f}"),"Notepad") ConsoleWrite("'f' key will now open notepad" & @CRLF) ConsoleWrite("'a' to switch hotkey" & @CRLF) ConsoleWrite("'esc' to stop script" & @CRLF) Local $vhotkey = 0 While Sleep (100) If _IsPressed("41") AND $vhotkey = 0 Then ;41 = a ConsoleWrite("'f' key will now open calulator" & @CRLF) HotKeySet(("{f}"),"Calc") $vhotkey = 1 ElseIf _IsPressed("41") AND $vhotkey = 1 Then ;41 = a ConsoleWrite("'f' key will now open notepad" & @CRLF) HotKeySet(("{f}"),"Notepad") $vhotkey = 0 EndIf WEnd Func Notepad() Run("notepad.exe") EndFunc Func Calc() Run("calc.exe") EndFunc Func Terminate() Exit EndFunc You could try something like this. Change notepad and calc to a msgbox if you need to test. Ohh perfect, thanks a lot! Will incorporate this into my script Link to comment Share on other sites More sharing options...
Dxnny Posted November 25, 2019 Author Share Posted November 25, 2019 expandcollapse popup#include <Misc.au3> $dll = DllOpen("user32.dll") Global $Paused HotKeySet("{NUMPADSUB}", "TogglePause") HotKeySet("{NUMPADENTER}", "Terminate") Local $vhotkey = 0 While Sleep (100) If _IsPressed("6A") AND $vhotkey = 0 Then ;6A = * ConsoleWrite("Cat A hotkeys will now work" & @CRLF) If _IsPressed("46", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 252, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("47", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 348, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("48", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 444, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("4A", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 540, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("4B", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 814, 513, 1 ) Sleep (100) Send ("I") EndIf $vhotkey = 1 ElseIf _IsPressed("6A") AND $vhotkey = 1 Then ;6A = * ConsoleWrite("Cat B hotkeys will now work" & @CRLF) If _IsPressed("46", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 728, 252, 736, 684, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("47", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 728, 348, 736, 684, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("48", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 728, 444, 736, 684, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("4A", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 728, 540, 736, 684, 1 ) Sleep (100) Send ("I") EndIf If _IsPressed("4B", $dll) Then Send ("I") Sleep (5001) MouseClickDrag("left", 814, 513, 736, 684, 1 ) Sleep (100) Send ("I") EndIf DllClose($dll) $vhotkey = 0 EndIf WEnd Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) WEnd EndFunc Func Terminate() Exit 0 EndFunc Ok, so it didn't work, this is what I've got. Link to comment Share on other sites More sharing options...
Nine Posted November 25, 2019 Share Posted November 25, 2019 What are all those mouse drag ? I wonder if there would be a better approach. What is the application you are trying to automate ? “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...
Dxnny Posted November 25, 2019 Author Share Posted November 25, 2019 7 minutes ago, Nine said: What are all those mouse drag ? I wonder if there would be a better approach. What is the application you are trying to automate ? Just a load of actions that I have to keep repeating, I just want the 2 categories to have the same hotkeys, would make things so much easier. Link to comment Share on other sites More sharing options...
Nine Posted November 25, 2019 Share Posted November 25, 2019 You did not answer my question. If you could tell us the name of the application, maybe someone will know it and give you a better solution. “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...
SkysLastChance Posted November 25, 2019 Share Posted November 25, 2019 (edited) There is probably a way easier way to do this. However using my code you would need to do this. expandcollapse popup#include <Misc.au3> HotKeySet(("{ESC}"),"Terminate") HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatB_G") ;... add more keys ConsoleWrite("'f' and 'g' key will now us CatA" & @CRLF) ConsoleWrite("'a' to switch to CatB" & @CRLF) ConsoleWrite("'esc' to stop script" & @CRLF) Local $vhotkey = 0 ;$vhotkey =0 starts on category A $vhotkey =1 starts on category B While $vhotkey = 1 or $vhotkey = 0 If _IsPressed("41") AND $vhotkey = 0 Then ;41 = 'A' key ConsoleWrite("Cat A hotkeys will now work" & @CRLF) HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatB_G") ;... add more keys Sleep (100) $vhotkey = 1 ElseIf _IsPressed("41") AND $vhotkey = 1 Then ;41 = 'A' key ConsoleWrite("Cat B hotkey will now work" & @CRLF) HotKeySet(("{f}"),"CatB_F") HotKeySet(("{g}"),"CatB_G") ;... add more keys Sleep (100) $vhotkey = 0 EndIf ;......your code WEnd Func CatA_F() ;Category A 'F' Key Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 252, 1 ) Sleep (100) Send ("I") EndFunc Func CatB_F() ;Cateogry B 'F' Key Send ("I") Sleep (5001) MouseClickDrag("left", 728, 252, 736, 684, 1 ) Sleep (100) Send ("I") EndFunc Func CatA_G() ;Cateogry A 'G' Key Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 348, 1 ) Sleep (100) Send ("I") EndFunc Func CatB_G() ;Category B 'G' Key Send ("I") Sleep (5001) MouseClickDrag("left", 728, 348, 736, 684, 1 ) Sleep (100) Send ("I") EndFunc ;add more funchs Func Terminate() Exit EndFunc Edited November 26, 2019 by SkysLastChance You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott Link to comment Share on other sites More sharing options...
Dxnny Posted November 26, 2019 Author Share Posted November 26, 2019 11 hours ago, SkysLastChance said: There is probably a way easier way to do this. However using my code you would need to do this. expandcollapse popup#include <Misc.au3> HotKeySet(("{ESC}"),"Terminate") HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatB_G") ;... add more keys ConsoleWrite("'f' and 'g' key will now us CatA" & @CRLF) ConsoleWrite("'a' to switch to CatB" & @CRLF) ConsoleWrite("'esc' to stop script" & @CRLF) Local $vhotkey = 0 ;$vhotkey =0 starts on category A $vhotkey =1 starts on category B While $vhotkey = 1 or $vhotkey = 0 If _IsPressed("41") AND $vhotkey = 0 Then ;41 = 'A' key ConsoleWrite("Cat A hotkeys will now work" & @CRLF) HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatB_G") ;... add more keys $vhotkey = 1 ElseIf _IsPressed("41") AND $vhotkey = 1 Then ;41 = 'A' key ConsoleWrite("Cat B hotkey will now work" & @CRLF) HotKeySet(("{f}"),"CatB_F") HotKeySet(("{g}"),"CatB_G") ;... add more keys $vhotkey = 0 EndIf ;......your code WEnd Func CatA_F() ;Category A 'F' Key Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 252, 1 ) Sleep (100) Send ("I") EndFunc Func CatB_F() ;Cateogry B 'F' Key Send ("I") Sleep (5001) MouseClickDrag("left", 728, 252, 736, 684, 1 ) Sleep (100) Send ("I") EndFunc Func CatA_G() ;Cateogry A 'G' Key Send ("I") Sleep (5001) MouseClickDrag("left", 736, 684, 728, 348, 1 ) Sleep (100) Send ("I") EndFunc Func CatB_G() ;Category B 'G' Key Send ("I") Sleep (5001) MouseClickDrag("left", 728, 348, 736, 684, 1 ) Sleep (100) Send ("I") EndFunc Func Terminate() Exit EndFunc Will try this when I’m home, thank you Link to comment Share on other sites More sharing options...
Dxnny Posted November 26, 2019 Author Share Posted November 26, 2019 6 hours ago, Dxnny said: Will try this when I’m home, thank you Hey, it's still not working When I press the button to switch to the other category, it spams the message repeatedly in console Cat A hotkeys will now work Cat B hotkey will now work And it switches to the other category but doesn't let me switch back Link to comment Share on other sites More sharing options...
SkysLastChance Posted November 26, 2019 Share Posted November 26, 2019 I edited my response. You just needed a sleep. You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott Link to comment Share on other sites More sharing options...
Dxnny Posted November 27, 2019 Author Share Posted November 27, 2019 (edited) 23 hours ago, SkysLastChance said: I edited my response. You just needed a sleep. Thank you, that fixed it. How would I go about making a hotkey to toggle pause the entire script so I can use the keys as normal to type. I've tried adding a hotkey bound to this function: Func TogglePause() $Paused = NOT $Paused ConsoleWrite("Script is now being paused/resumed" & @CRLF) While $Paused sleep(100) WEnd EndFunc And it writes to console but doesn't pause the script. Edited November 27, 2019 by Dxnny Link to comment Share on other sites More sharing options...
SkysLastChance Posted November 27, 2019 Share Posted November 27, 2019 expandcollapse popup#include <Misc.au3> #include <AutoItConstants.au3> HotKeySet(("{ESC}"),"Terminate") HotKeySet(("{p}"),"TogglePause") HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatA_G") ConsoleWrite("'a' to switch hotkey" & @CRLF) ConsoleWrite("'esc' to stop script" & @CRLF) ConsoleWrite("'p' to toggle pause" & @CRLF) Global $Paused,$vhotkey = 0 While Sleep (50) If _IsPressed("41") AND $vhotkey = 1 Then ;41 = a Sleep (100) ConsoleWrite("Cat A hotkeys will now work" & @CRLF) HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatA_G") $vhotkey = 0 ElseIf _IsPressed("41") AND $vhotkey = 0 Then ;41 = a Sleep (100) ConsoleWrite("Cat B hotkeys will now work" & @CRLF) HotKeySet(("{f}"),"CatB_F") HotKeySet(("{g}"),"CatB_G") $vhotkey = 1 EndIf WEnd Func CatA_F() ConsoleWrite("A_F" & @CRLF) EndFunc Func CatB_F() ConsoleWrite("B_F" & @CRLF) EndFunc Func CatA_G() ConsoleWrite("A_G" & @CRLF) EndFunc Func CatB_G() ConsoleWrite("B_G" & @CRLF) EndFunc Func Terminate() Exit EndFunc Func TogglePause() $Paused = NOT $Paused If $Paused = True Then ConsoleWrite("Hotkeys Disabled" & @CRLF) HotKeySet(("{f}"),"DisableHotKey") HotKeySet(("{g}"),"DisableHotKey") ;add hotkeys that you want to be disabled during the pause ElseIf $Paused = False Then Switch $vhotkey = $vhotkey Case $vhotkey = 0 HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatA_G") ;add Cat A Keys` ConsoleWrite("Hotkeys Enabled Cat A" & @CRLF) Case $vhotkey = 1 HotKeySet(("{f}"),"CatB_F") HotKeySet(("{g}"),"CatB_G") ConsoleWrite("Hotkeys Enabled Cat Baaaaaaaaaa" & @CRLF) ;add Cat B keys EndSwitch EndIf EndFunc Func DisableHotKey() ConsoleWrite("Push 'a' to enable hotkeys" & @CRLF) EndFunc This will work. 😕 It's not pretty but it will work. You just need to make sure you add the keys to the pause section as well. If you give a better idea of what you are trying to do someone a lot smarter than me can help you do this a lot easier and with a lot less code. You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott Link to comment Share on other sites More sharing options...
Dxnny Posted November 28, 2019 Author Share Posted November 28, 2019 21 hours ago, SkysLastChance said: expandcollapse popup#include <Misc.au3> #include <AutoItConstants.au3> HotKeySet(("{ESC}"),"Terminate") HotKeySet(("{p}"),"TogglePause") HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatA_G") ConsoleWrite("'a' to switch hotkey" & @CRLF) ConsoleWrite("'esc' to stop script" & @CRLF) ConsoleWrite("'p' to toggle pause" & @CRLF) Global $Paused,$vhotkey = 0 While Sleep (50) If _IsPressed("41") AND $vhotkey = 1 Then ;41 = a Sleep (100) ConsoleWrite("Cat A hotkeys will now work" & @CRLF) HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatA_G") $vhotkey = 0 ElseIf _IsPressed("41") AND $vhotkey = 0 Then ;41 = a Sleep (100) ConsoleWrite("Cat B hotkeys will now work" & @CRLF) HotKeySet(("{f}"),"CatB_F") HotKeySet(("{g}"),"CatB_G") $vhotkey = 1 EndIf WEnd Func CatA_F() ConsoleWrite("A_F" & @CRLF) EndFunc Func CatB_F() ConsoleWrite("B_F" & @CRLF) EndFunc Func CatA_G() ConsoleWrite("A_G" & @CRLF) EndFunc Func CatB_G() ConsoleWrite("B_G" & @CRLF) EndFunc Func Terminate() Exit EndFunc Func TogglePause() $Paused = NOT $Paused If $Paused = True Then ConsoleWrite("Hotkeys Disabled" & @CRLF) HotKeySet(("{f}"),"DisableHotKey") HotKeySet(("{g}"),"DisableHotKey") ;add hotkeys that you want to be disabled during the pause ElseIf $Paused = False Then Switch $vhotkey = $vhotkey Case $vhotkey = 0 HotKeySet(("{f}"),"CatA_F") HotKeySet(("{g}"),"CatA_G") ;add Cat A Keys` ConsoleWrite("Hotkeys Enabled Cat A" & @CRLF) Case $vhotkey = 1 HotKeySet(("{f}"),"CatB_F") HotKeySet(("{g}"),"CatB_G") ConsoleWrite("Hotkeys Enabled Cat Baaaaaaaaaa" & @CRLF) ;add Cat B keys EndSwitch EndIf EndFunc Func DisableHotKey() ConsoleWrite("Push 'a' to enable hotkeys" & @CRLF) EndFunc This will work. 😕 It's not pretty but it will work. You just need to make sure you add the keys to the pause section as well. If you give a better idea of what you are trying to do someone a lot smarter than me can help you do this a lot easier and with a lot less code. Didn't seem to work 🤔 Link to comment Share on other sites More sharing options...
SkysLastChance Posted November 29, 2019 Share Posted November 29, 2019 Didn't seem to work tells me nothing... You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott 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