orly2173 Posted September 10, 2015 Share Posted September 10, 2015 Hello there,I was trying to make a script which starts by pressing the middle mousebutton and pauses by pressing the middle mouse button.I already did some research and found out, that you can't use the middle mouse button as a hotkey through HotKeySet.But you can use _IsPressedThis is my code so far#include <misc.au3> Global $A = 0 while (1) If _IsPressed(4) Then If $A = 0 Then $A = 1 Else $A = 0 EndIf EndIf If $A Then Send ("{ENTER}", 0) Sleep (1000) EndIf WEndThe script basically starts when I press the middle Mouse button but it doesn't pause when I press it.I think the Problem is that _IsPressed(4) only scans between 2-1000-millisecond-sleep-intervals,If any of you guys have an idea how to solve this problem I would be very glad. Thanks in advance Link to comment Share on other sites More sharing options...
BrewManNH Posted September 10, 2015 Share Posted September 10, 2015 The _IsPressed function doesn't require a long sleep, it will detect the key very quickly. The problem with your script is that you have too long of a sleep in the loop, and it's in the wrong place.Here's a modification that should do what you're attempting to do, it should give you a better idea of where to go from here.#include <misc.au3> Global $A = False While (1) If _IsPressed(4) Then $A = Not $A While _IsPressed(4) ; prevents the _IsPressed from retriggering until you've released the button WEnd EndIf If $A = True Then ;~ Send("{ENTER}", 0) ConsoleWrite("Test" & @CRLF) EndIf Sleep(100) ; sleep should be outside the previous If conditional, and 1 second is a little too long to detect quick key presses. WEnd orly2173 1 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...
orly2173 Posted September 10, 2015 Author Share Posted September 10, 2015 The _IsPressed function doesn't require a long sleep, it will detect the key very quickly. The problem with your script is that you have too long of a sleep in the loop, and it's in the wrong place.Here's a modification that should do what you're attempting to do, it should give you a better idea of where to go from here.#include <misc.au3> Global $A = False While (1) If _IsPressed(4) Then $A = Not $A While _IsPressed(4) ; prevents the _IsPressed from retriggering until you've released the button WEnd EndIf If $A = True Then ;~ Send("{ENTER}", 0) ConsoleWrite("Test" & @CRLF) EndIf Sleep(100) ; sleep should be outside the previous If conditional, and 1 second is a little too long to detect quick key presses. WEnd First of all thank you for your answer.I tried it and it works great!If I want the script to Press Enter, then sleep for 500ms and then Press the "A"-Key - where am I supposed to place the Sleep then? Thank you BogdanNicolescu 1 Link to comment Share on other sites More sharing options...
BrewManNH Posted September 10, 2015 Share Posted September 10, 2015 You can do it all in one Send command if you want to alter the SendKeyDelay time to 500msSendKeyDelay Alters the length of the brief pause in between sent keystrokes. A value of 0 removes the delay completely. Time in milliseconds to pause (default=5). orly2173 1 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...
orly2173 Posted September 10, 2015 Author Share Posted September 10, 2015 (edited) You can do it all in one Send command if you want to alter the SendKeyDelay time to 500msSendKeyDelay Alters the length of the brief pause in between sent keystrokes. A value of 0 removes the delay completely. Time in milliseconds to pause (default=5). Thanks alot - it works. The last thing that bothers me is that sometimes when i press the middle mouse button it doesnt trigger (pause) but I guess that is not fixable? Edited September 10, 2015 by orly2173 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