MattC Posted December 14, 2009 Share Posted December 14, 2009 Hello I'm trying to write a script that will "hold" down Ctrl , then wait for a single digit number ( 0,1,2,3,4,5,6,7,8,9) then automatically release Ctrl... Is this possible with Autoit???? The goal is to assign hotkeys to Ctrl+1, Ctrl+2, ect... to open certain files on my harddrive and I'm going to map this script on one of my remote control buttons so I can hit it, then hit a number to launch the file any help would be great! Thanks Link to comment Share on other sites More sharing options...
ichigo325 Posted December 14, 2009 Share Posted December 14, 2009 You can use HotKeySet, much more easier but you can try my code. I make it monitor the numbers (1,2,3...9), when you press the number, it will automatically send CTRL key + number you've pressed... #include <String.au3> #include <Misc.au3> While 1 For $x = 30 To 39 ;monitoring number key If _IsPressed($x) = 1 Then _SendKey($x) EndIf Next For $x = 60 To 69 ; monitoring "keypad" number key If _IsPressed($x) = 1 Then For $i = $x To 69 If $x = $i Then $x -= 30 Next _SendKey($x) EndIf Next Sleep(100) ; idle the script, the value can be reduced for faster response but will increase cpu usage WEnd Func _SendKey($key) $key = _HexToString($key) Send("^" & $key) MsgBox(0, "", "You've press CTRL+" & $key) EndFunc ;==>_SendKey [size="2"][font="Lucida Sans Unicode"][b][/b][/font][/size] Link to comment Share on other sites More sharing options...
MattC Posted December 14, 2009 Author Share Posted December 14, 2009 You can use HotKeySet, much more easier but you can try my code. I make it monitor the numbers (1,2,3...9), when you press the number, it will automatically send CTRL key + number you've pressed... #include <String.au3> #include <Misc.au3> While 1 For $x = 30 To 39 ;monitoring number key If _IsPressed($x) = 1 Then _SendKey($x) EndIf Next For $x = 60 To 69 ; monitoring "keypad" number key If _IsPressed($x) = 1 Then For $i = $x To 69 If $x = $i Then $x -= 30 Next _SendKey($x) EndIf Next Sleep(100) ; idle the script, the value can be reduced for faster response but will increase cpu usage WEnd Func _SendKey($key) $key = _HexToString($key) Send("^" & $key) MsgBox(0, "", "You've press CTRL+" & $key) EndFunc ;==>_SendKey Thanks for the reply! Very interesting approach, I'm very new to programming....I'll mess with it more after work, but I have a few questions.. Once I run this script and hit a number key, will the script quit, allowing me to hit the 0-9 keys normally (no Ctrl) until i run the script again? Now that I think about it, I would like it to respond to "any" key rather than just the 0-9 keys.... how hard would that be? About AutoHotkey, how would I make that "tongle" Ctrl? I can figure out how to make it ALWAYS hit Ctrl when I press 0-9 .. but not have a button on my PC remote toggle Ctrl when I press it (I'm going to assign this script to a button on my remote control, so I can press it, then press a number on the keypad) Thanks! Link to comment Share on other sites More sharing options...
MattC Posted December 14, 2009 Author Share Posted December 14, 2009 (edited) OR .... is there something you could add to your original code that would do something like... IF a key is pressed that IS NOT 0-9 ... it cancles the script?? THAT would be the IDEAL script because if for some reason I accedently hit the button on the remote, the script will keep waiting for a 0-9 key to be pressed Edited December 14, 2009 by MattC Link to comment Share on other sites More sharing options...
ichigo325 Posted December 15, 2009 Share Posted December 15, 2009 Hi, the script will not response to any buttons you press unless it is 0-9, what i mean is you can still press other buttons without any problems.. So, don't worry if you're accidentally pressed other buttons.. But, you can assign any button to cancel the script such as "Delete".. Try some experiment with your script, read the AutoIt Help file for further information.. [size="2"][font="Lucida Sans Unicode"][b][/b][/font][/size] 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