Ryusenko Posted February 8, 2014 Posted February 8, 2014 Hi. I want to make a script that changes an extra mouse button into Ctrl. If that isn't possible, I would like to have another key replace Ctrl. I want the script to have CTRLDOWN when the key is pressed down and CTRLUP when the key is released. I've been researching and am not sure if i should use a function or an if...then statement to make this work.
nullschritt Posted February 8, 2014 Posted February 8, 2014 Use _WinAPI_SetWindowsHookEx() to detect the push and release of the extra mouse button. When pushed send("lctrl down}") and when released send("lctrl up}").
somdcomputerguy Posted February 8, 2014 Posted February 8, 2014 You can use this function (instead if you wish) to detect the 'keypress', and then Send whatever you need based on that. http://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
Ryusenko Posted February 8, 2014 Author Posted February 8, 2014 Sorry, the mouse button isn't working as i thought it would. Is it possible to make it so that I press a key to activate CTRLDOWN and release that key to activate CTRLUP?
Ryusenko Posted February 8, 2014 Author Posted February 8, 2014 One of my attempts for the script is this: #RequireAdmin #include <Misc.au3> $dll = DllOpen("user32.dll") While 1 Sleep ( 250 ) If _IsPressed(26, $dll) Then Send("{CTRLDOWN}") EndIf WEnd Send("{CTRLUP}") The script doesn't work as I intend because CTRL constantly stays down. And if i unlock it, then the script doesn't seem to work anymore.
somdcomputerguy Posted February 8, 2014 Posted February 8, 2014 (edited) Add this line to the If loop If _IsPressed(28, $dll) Then Send("{CTRLUP}") And get rid of the last line in your script. Edited February 8, 2014 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
BlackDawn187 Posted February 8, 2014 Posted February 8, 2014 Also, DllClose($dLL) Wouldn't hurt either..
Ryusenko Posted February 8, 2014 Author Posted February 8, 2014 Can i make it so that one key represents CTRL?
somdcomputerguy Posted February 8, 2014 Posted February 8, 2014 Look at the example code for the _IsPressed function. Notice the use of two While loops, one within the other? More specifically, the While in the If? - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
Solution Ryusenko Posted February 8, 2014 Author Solution Posted February 8, 2014 Thank You. Finally got it. Script ended up being like this. #RequireAdmin #include <Misc.au3> $dll = DllOpen("user32.dll") While 1 Sleep ( 250 ) If _IsPressed(26, $dll) Then Send("{CTRLDOWN}") ; Wait until key is released. While _ISPressed(26, $dll) Sleep(250) WEnd Send("{CTRLUP}") EndIf Sleep(250) WEnd DllClose($dLL)
somdcomputerguy Posted February 8, 2014 Posted February 8, 2014 (edited) Way to go man. Good luck with the rest of your project. You really should put in some way to exit out of that first loop though. The way you have it written, DLLClose will never be executed. It may not matter, especially if you want this script to just run forever, all the time, but good code should have a way of gracefully exiting. See the HotKeySet function.. Edited February 8, 2014 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
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