Wouter Posted December 21, 2005 Share Posted December 21, 2005 Hello everyone, I've been trying to write a script for use in a CAD program which does the following: When I press and hold a single key, e.g. F1 the script should press and hold down SHIFT and the middle mouse button down. Then when I release the key again, it should 'unpress' these buttons again. I've been playing with a hotkey script that sends keydown and keyup commands, but it doesn't unpress and it slows down the computer very much. Below is how it looks a.t.m. Does anyone know how to get this thing working? Or a totally different approach that would work? Thanks in advance! Script: -------- Global $Mouse HotKeySet("{F1}", "move") HotKeySet("{F5}", "Terminate") While 1 Sleep(100) WEnd Func move() ;toggle $mouse between 0 and 1 (false / true) $Mouse = NOT $Mouse While $Mouse = 1 Send("{SHIFTDOWN}") MouseDown("middle") WEnd Send("{SHIFTUP}") MouseUp("middle") EndFunc Func Terminate() Exit 0 EndFunc Link to comment Share on other sites More sharing options...
lopolop Posted December 21, 2005 Share Posted December 21, 2005 did u try _IsPressed ? Link to comment Share on other sites More sharing options...
MrSpacely Posted December 21, 2005 Share Posted December 21, 2005 (edited) did u try _IsPressed ?Only for reading the F1 indeed Edited December 21, 2005 by MrSpacely Link to comment Share on other sites More sharing options...
MrSpacely Posted December 21, 2005 Share Posted December 21, 2005 (edited) #Include <Misc.au3> HotKeySet("{F5}", "Terminate") While 1 Sleep(100) If _IsPressed("70") Then ToolTip("down") Send("{SHIFTDOWN}") MouseDown("middle") While _IsPressed("70") Sleep(10) WEnd ToolTip("") MouseUp("middle") Send("{SHIFTUP}") EndIf WEnd Func Terminate() Exit 0 EndFunc nice code Hmm it is what he wanted weird I just fixed his code but that one toggled it Hmm anyway here the code I thought he wanted maybe someone find it usefull expandcollapse popupHotKeySet("{F1}", "move") HotKeySet("+{F1}", "move") HotKeySet("{F5}", "Terminate") HotKeySet("+{F5}", "Terminate") global $Mouse = -2 While 1 Sleep(100) if $Mouse = 1 then Send("{SHIFTDOWN}") MouseDown("middle") beep(1000,100) $Mouse = 2 endif if $Mouse = -1 then Send("{SHIFTUP}") MouseUp("middle") beep(800,100) $Mouse = -2 endif SplashTextOn ( "bla", $Mouse, 100,100, 0 ,0) WEnd Func move() ;toggle $mouse between 0 and 1 (false / true) if $Mouse = 2 then $Mouse = -1 elseif $Mouse = -2 then $Mouse = 1 endif EndFunc Func Terminate() Send("{SHIFTUP}") MouseUp("middle") Exit 0 EndFunc Edited December 21, 2005 by MrSpacely Link to comment Share on other sites More sharing options...
Zest Posted December 21, 2005 Share Posted December 21, 2005 First of all, thank you all for the megafast replies! @ Larry: My Autoit version (3.1.1) doesn't know about '_ispressed' (and neither about 'beep'), so I seem to need the latest beta version :-) I will try this tomorrow. @ MrSpacely: Although you programmed the key to have a toggle function (instead of having to hold it pressed down), it seems to be working great without slowing down te program! :-) Thank you both! I will try to make some extra adjustments I just thought of and will bother you again if I have another problem :-) Link to comment Share on other sites More sharing options...
Zest Posted December 21, 2005 Share Posted December 21, 2005 OK, now I'm REALLY confused. For another use I've been trying this for CTRL also by just replacing every instance of SHIFT with CTRL like this: expandcollapse popupHotKeySet("{F1}", "move") HotKeySet("+{F1}", "move") HotKeySet("{F5}", "Terminate") HotKeySet("+{F5}", "Terminate") global $Mouse = -2 While 1 Sleep(100) if $Mouse = 1 then Send("{CTRLDOWN}") MouseDown("middle") $Mouse = 2 endif if $Mouse = -1 then Send("{CTRLUP}") MouseUp("middle") $Mouse = -2 endif SplashTextOn ( "bla", $Mouse, 100,100, 0 ,0) WEnd Func move() ;toggle $mouse between 0 and 1 (false / true) if $Mouse = 2 then $Mouse = -1 elseif $Mouse = -2 then $Mouse = 1 endif EndFunc Func Terminate() Send("{CTRLUP}") MouseUp("middle") Exit 0 EndFunc But after testing half an hour it seems to me that Send("{CTRLUP}") does nothing! The script seems to pause somehow and CTRL keeps being pressed. Is this a bug or am I doing something wrong? BTW please ignore the other name, 'Zest' is my old login and I just found the old login after I had made a new account .... java script:emoticon("", smilie Link to comment Share on other sites More sharing options...
w0uter Posted December 21, 2005 Share Posted December 21, 2005 you could try {LCTRL DOWN} & {LCTRL UP} btw nice name My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
MrSpacely Posted December 21, 2005 Share Posted December 21, 2005 (edited) OK, now I'm REALLY confused. For another use I've been trying this for CTRL also by just replacing every instance of SHIFT with CTRL like this: expandcollapse popupHotKeySet("{F1}", "move") HotKeySet("+{F1}", "move") HotKeySet("{F5}", "Terminate") HotKeySet("+{F5}", "Terminate") global $Mouse = -2 While 1 Sleep(100) if $Mouse = 1 then Send("{CTRLDOWN}") MouseDown("middle") $Mouse = 2 endif if $Mouse = -1 then Send("{CTRLUP}") MouseUp("middle") $Mouse = -2 endif SplashTextOn ( "bla", $Mouse, 100,100, 0 ,0) WEnd Func move() ;toggle $mouse between 0 and 1 (false / true) if $Mouse = 2 then $Mouse = -1 elseif $Mouse = -2 then $Mouse = 1 endif EndFunc Func Terminate() Send("{CTRLUP}") MouseUp("middle") Exit 0 EndFunc But after testing half an hour it seems to me that Send("{CTRLUP}") does nothing! The script seems to pause somehow and CTRL keeps being pressed. Is this a bug or am I doing something wrong? BTW please ignore the other name, 'Zest' is my old login and I just found the old login after I had made a new account .... java script:emoticon("", smilie i understand why see HotKeySet("+{F1}", "move") the + sign is for shift I added this because when the program does shiftdown the hotkeysend will not respond quote from manual '!' This tells AutoIt to send an ALT keystroke, therefore Send("This is text!a") would send the keys "This is text" and then press "ALT+a". N.B. Some programs are very choosy about capital letters and ALT keys, i.e. "!A" is different to "!a". The first says ALT+SHIFT+A, the second is ALT+a. If in doubt, use lowercase! '+' This tells AutoIt to send a SHIFT keystroke, therefore Send("Hell+o") would send the text "HellO". Send("!+a") would send "ALT+SHIFT+a". '^' This tells AutoIt to send a CONTROL keystroke, therefore Send("^!a") would send "CTRL+ALT+a". So change the + sign in both hotkey sends with the + to ^ then it would work Functions not supported are because we both (larry and me(also lots of other people)) use beta why well the beta has lots of more functions. Only sometimes some bugs occur (not often actually) but these are fixed within days. I often use beta because its also more stable the 3.1.1 version crashed on me more then the beta Also if you use beta and find a bug you can just download a older beta wich doesn;t have that bug. Thats what I do but in my point of view the beta works well. ow yeah the fixed code also see that I removed the splashtexton that was just for testing also the beep was for testing (I forgot to remove that) HotKeySet("{F1}", "move") HotKeySet("^{F1}", "move") HotKeySet("{F5}", "Terminate") HotKeySet("^{F5}", "Terminate") global $Mouse = -2 While 1 Sleep(100) if $Mouse = 1 then Send("{CTRLDOWN}") MouseDown("middle") $Mouse = 2 endif if $Mouse = -1 then Send("{CTRLUP}") MouseUp("middle") $Mouse = -2 endif WEnd Func move() ;toggle $mouse between 0 and 1 (false / true) if $Mouse = 2 then $Mouse = -1 elseif $Mouse = -2 then $Mouse = 1 endif EndFunc Func Terminate() Send("{CTRLUP}") MouseUp("middle") Exit 0 EndFunc Edited December 21, 2005 by MrSpacely Link to comment Share on other sites More sharing options...
Zest Posted December 24, 2005 Share Posted December 24, 2005 Okay I got it all to work! Now I'm trying to combine both into 1 script, but I think I will get it right myself this time :-). I have already implemented a check so that the shortcuts only work while I'm in the correct program. Thank you all for your help! 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