Jump to content

[help] How To Effectively Use Array With Hotkeyset


Recommended Posts

Dim $Macro_Delay = 6000

For $n = 0 To 9
    HotKeySet("+"&$n&"", "NUMPAD")
Next

HotkeySet ("+{F10}", "Stop"); + = Shift Key

Opt ("WinTitleMatchMode", 3   )
Opt ("MouseClickDownDelay", 55)
Opt ("MouseClickDelay", 1    )
Opt ("SendKeyDownDelay", 10   )
Opt ("SendKeyDelay", 1      )
Opt ("CaretCoordMode", 2      )

Func NUMPAD (); Macros Through "ALT + 1" ~ "ALT + 0".
    While (1)
    If WinActive("MU") Then
        Dim $num[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; Alt +1 Till Alt +0.
        For $m = 1 To $num; Alt +1 ~ +$n
            Send ("!"&$m&""); Macro number.
            Sleep ($Macro_Delay)
        Next
    EndIf
    WEnd
EndFunc

Func Stop (); Stops The Program.
    While 1 = 1
        Sleep (1000)
    Wend
EndFunc

While (1); Continuous Loop Of Program.
    Sleep (1)
WEnd

Basically this is a macro bot that preses ALT + num.

my prob here is, the script just continues ALT +1 -> Alt +0.... which is abit out of my idea of how it should work.

$n will take the last value of ALT + $n.

Any pro can enlighten me?

Just new to the beta autoit scripting.... also a nub in autoit.

Link to comment
Share on other sites

  • Moderators

Could try this I guess

Func NUMPAD (); Macros Through "ALT + 1" ~ "ALT + 0".
    Local $num[12] = ['', 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; Alt +1 Till Alt +0.
    While 1
        If WinActive("MU") Then
            For $m = 1 To UBound($num) - 1; Alt +1 ~ +$n
                Send ("!" & $m ); Macro number.
                Sleep ($Macro_Delay)
            Next
        EndIf
        Sleep(10)
    WEnd
EndFunc
Your array was set for the wrong number of elements ... also take a look at the definition of Ubound() in the help file to understand what that is.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Wow, Thanks.

was wondering why the array has to start with ''

$num[12] = ['', 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
.....
For $m = 1 To UBound($num) - 1

Remarks

Remember that the value returned by UBound is one greater than the index of an array's last element!

So if i have 10 values, i'll need to use [12] instead, when im using UBound??

For $n = 0 To 9
    HotKeySet("+"&$n&"", "NUMPAD")
Next

for "Shift + $n" to link to the "ALT + $n"

If i press Hotkey "Shift + 5", the function will press Alt+1, Alt+2, Alt+3, Alt+4, Alt+5.

Will try again and feedback my results.

Link to comment
Share on other sites

  • Moderators

Remember that the value returned by UBound is one greater than the index of an array's last element!

So if i have 10 values, i'll need to use [12] instead, when im using UBound??

No, if you have 10 elements, if not using 0, then you return will be minus one. So, It would be 11, in this instance.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Dim $Macro_Delay = 6000

For $n = 0 To 9
    HotKeySet("+"&$n&"", "NUMPAD")
Next

HotkeySet ("+{F10}", "Stop"); + = Shift Key

Opt ("WinTitleMatchMode", 3   )
Opt ("MouseClickDownDelay", 55)
Opt ("MouseClickDelay", 1    )
Opt ("SendKeyDownDelay", 10   )
Opt ("SendKeyDelay", 1      )
Opt ("CaretCoordMode", 2      )

Func NUMPAD (); Macros Through "ALT + 1" ~ "ALT + 0".
    While (1)
        If $n = 0 Then
            $n = 10
        EndIf
        If WinActive("MU") Then
            For $m = 1 To $n; Alt +1 ~ +$n
                If $m = 10 Then
                    $m = 0
                EndIf
                Send ("!"&$m);  Macro number.
                Sleep ($Macro_Delay)
            Next
        EndIf
    WEnd
EndFunc

Func Stop (); Stops The Program.
    While 1 = 1
        Sleep (1000)
    Wend
EndFunc

While (1); Continuous Loop Of Program.
    Sleep (1)
WEnd

It turns out that i am using this format for my code.... since i can't implement my code the wat i wanted. but my prob still exist.....

For $n = 0 To 9
    HotKeySet("+"&$n&"", "NUMPAD")
Next

This seems to be my prob, cos my script just ran Alt+1 all the way to the end (Alt+0) instead of the $n i pressed.

Your code did work too (UBound) but since there's also no usage on the "$n" part, it also gets the same problem in the end.

Edited by zzxxzzxx
Link to comment
Share on other sites

Dim $Macro_Delay = 6000

For $numpad = 0 To 9
    HotKeySet("+"&$numpad&"", "NUMPAD")
Next

HotkeySet ("+{F10}", "Stop"); + = Shift Key

Opt ("WinTitleMatchMode", 3   )
Opt ("MouseClickDownDelay", 55)
Opt ("MouseClickDelay", 1    )
Opt ("SendKeyDownDelay", 10   )
Opt ("SendKeyDelay", 1      )
Opt ("CaretCoordMode", 2      )

Func NUMPAD (); Macros Through "ALT + 1" ~ "ALT + 0".
    $numpad = StringTrimLeft (@HotKeyPressed, 1)
    While (1)
        If $numpad = 0 Then
            $numpad = 10
        EndIf
        If WinActive("MU") Then
            For $macro = 1 To $numpad; Alt +1 ~ +$n
                If $macro = 10 Then
                    $macro = 0
                EndIf
                Send ("!"&$macro);  Macro number.
                Sleep ($Macro_Delay)
            Next
        EndIf
    WEnd
EndFunc

Func Stop (); Stops The Program.
    While 1 = 1
        Sleep (1)
    Wend
EndFunc

While (1); Continuous Loop Of Program.
    Sleep (1)
WEnd

Well, this is my complete script and its kinda working alright, but a glitch .... i cant find out what caused it.

eg, when i press "Shift+5", the script SOMETIMES goes from ALT+1, ALT+2, ALT+3, ALT+4, ALT+5 and repeats.

But sometime it starts with ALT+5 instead, or what ever Shift+X i press.

The nice thing is even thou it starts with ALT+5, the repeat sequence is back to ALT+1 which is what i wanted.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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