Jump to content

Recommended Posts

Posted

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

Posted

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]

Posted

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!

Posted (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 by MattC
Posted

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.. :evil: 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]

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...