Cybazaar Posted May 18, 2018 Share Posted May 18, 2018 Hello everyone, I am using AutoIt for a short time now (just as a hobby), mostly trying to automate my workplace because our IT are too lazy to fulfill our needs for anything. Anyways, i've created a script that fits my needs and works just i have planned it. As you will see, i use 2 different keys to perform 2 actions and now my question is, is there any way, and how, to use instead the same key so that it performs the first action on its first time being pressed, and then perform the second action the second time it is being pressed (and maybe loop back to the first state but this is not mandatory at all, just got it on my mind now). Here it is what my script looks like: While 1 If WinActive ("[CLASS:AcrobatSDIWindow]") Then If _IsPressed("6A") Then Send ("^c") WinActivate ("[CLASS:OMain]", "") WinMove("[CLASS:OMain]", "", 0, 300, 1280, 702) MouseMove (270, 610, 0) MouseClick ($MOUSE_CLICK_LEFT) Send ("^v") WinActivate ("[CLASS:AcrobatSDIWindow]", "") ElseIf _IsPressed("6D") Then Send ("^c") WinActivate ("[CLASS:OMain]", "") WinMove("[CLASS:OMain]", "", 0, 300, 1280, 702) MouseMove (500, 610, 0) MouseClick ($MOUSE_CLICK_LEFT) Send ("^v") EndIf EndIf WEnd I would like to merge 6A and 6D into just 6A. Thanks in advance for your help! Link to comment Share on other sites More sharing options...
RTFC Posted May 18, 2018 Share Posted May 18, 2018 (edited) Local $firstPress=True While 1 If WinActive ("[CLASS:AcrobatSDIWindow]") Then If _IsPressed("6A") Then Send ("^c") WinActivate ("[CLASS:OMain]", "") WinMove("[CLASS:OMain]", "", 0, 300, 1280, 702) If $firstPress=True Then MouseMove (270, 610, 0) MouseClick ($MOUSE_CLICK_LEFT) Send ("^v") WinActivate ("[CLASS:AcrobatSDIWindow]", "") Else MouseMove (500, 610, 0) MouseClick ($MOUSE_CLICK_LEFT) Send ("^v") EndIf $firstPress=Not $firstPress EndIf EndIf WEnd Edit: one missing Endif added. Edited May 18, 2018 by RTFC My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
BrewManNH Posted May 18, 2018 Share Posted May 18, 2018 You could try something like this: $Toggle = False While 1 If WinActive("[CLASS:AcrobatSDIWindow]") Then If _IsPressed("6A") And $Toggle = False Then Send("^c") WinActivate("[CLASS:OMain]", "") WinMove("[CLASS:OMain]", "", 0, 300, 1280, 702) MouseMove(270, 610, 0) MouseClick($MOUSE_CLICK_LEFT) Send("^v") WinActivate("[CLASS:AcrobatSDIWindow]", "") $Toggle = True elseifIf _IsPressed("6A") And $Toggle = True Then Send("^c") WinActivate("[CLASS:OMain]", "") WinMove("[CLASS:OMain]", "", 0, 300, 1280, 702) MouseMove(500, 610, 0) MouseClick($MOUSE_CLICK_LEFT) Send("^v") $Toggle = False EndIf EndIf WEnd If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Cybazaar Posted May 18, 2018 Author Share Posted May 18, 2018 24 minutes ago, RTFC said: Local $firstPress=True While 1 If WinActive ("[CLASS:AcrobatSDIWindow]") Then If _IsPressed("6A") Then Send ("^c") WinActivate ("[CLASS:OMain]", "") WinMove("[CLASS:OMain]", "", 0, 300, 1280, 702) If $firstPress=True Then MouseMove (270, 610, 0) MouseClick ($MOUSE_CLICK_LEFT) Send ("^v") WinActivate ("[CLASS:AcrobatSDIWindow]", "") Else MouseMove (500, 610, 0) MouseClick ($MOUSE_CLICK_LEFT) Send ("^v") EndIf $firstPress=Not $firstPress EndIf WEnd I don't know why, but it didn't work, it had something to do with Wend But anyways 8 minutes ago, BrewManNH said: You could try something like this: $Toggle = False While 1 If WinActive("[CLASS:AcrobatSDIWindow]") Then If _IsPressed("6A") And $Toggle = False Then Send("^c") WinActivate("[CLASS:OMain]", "") WinMove("[CLASS:OMain]", "", 0, 300, 1280, 702) MouseMove(270, 610, 0) MouseClick($MOUSE_CLICK_LEFT) Send("^v") WinActivate("[CLASS:AcrobatSDIWindow]", "") $Toggle = True elseifIf _IsPressed("6A") And $Toggle = True Then Send("^c") WinActivate("[CLASS:OMain]", "") WinMove("[CLASS:OMain]", "", 0, 300, 1280, 702) MouseMove(500, 610, 0) MouseClick($MOUSE_CLICK_LEFT) Send("^v") $Toggle = False EndIf EndIf WEnd This works perfectly, just that you made a typo on line 24 writing elseifIF. Thanks a lot folks, im happy to learn 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