Jump to content

loop goto


chie
 Share

Recommended Posts

Now this is wery confusing i tried in many ways but I just cant seem to make it work the way i want it to & even browsing the help file for hours & no progress... :lmao:

so basically:

every time i press c pog hits once Left CTRL+v, & if i press c again same action is repeated.

Well so far it works but it presses CTRL+v only once for some reason....so please help me.

Forgot: Im using

SciTE

Version 1.71

This is my little code....

HotKeySet("c", "inventory")  ;Hotkey to open inventory
HotKeySet("m", "map")       ;Hotkey to open map 
HotKeySet("^!x", "MyExit") ;LCTRL+ALT+X Hotkey to exit program 

While 1
    Sleep(10)
WEnd

Func inventory()
    HotKeySet("c") ; un-register hotkey, so next line wont call it again
    Send("^v") ; send LeftCtrl+v
EndFunc

Func map()
    HotKeySet("m") ; un-register hotkey, so next line wont call it again
    Send("^m") ; send LeftCtrl+m
EndFunc

;Function to exit prog
Func MyExit()
    Exit 
EndFunc
Edited by chie
Link to comment
Share on other sites

Now this is wery confusing i tried in many ways but I just cant seem to make it work the way i want it to & even browsing the help file for hours & no progress... :lmao:

so basically:

every time i press c pog hits once Left CTRL+v, & if i press c again same action is repeated.

Well so far it works but it presses CTRL+v only once for some reason....so please help me.

Forgot: Im using

SciTE

Version 1.71

This is my little code....

HotKeySet("c", "inventory")  ;Hotkey to open inventory
HotKeySet("m", "map")       ;Hotkey to open map 
HotKeySet("^!x", "MyExit") ;LCTRL+ALT+X Hotkey to exit program 

While 1
    Sleep(10)
WEnd

Func inventory()
    HotKeySet("c") ; un-register hotkey, so next line wont call it again
    Send("^v") ; send LeftCtrl+v
EndFunc

Func map()
    HotKeySet("m") ; un-register hotkey, so next line wont call it again
    Send("^m") ; send LeftCtrl+m
EndFunc

;Function to exit prog
Func MyExit()
    Exit 
EndFunc

I hope the above helps you further your AutoIt knowledge.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

It took a while & after experimenting until the idea came to me: I used case thing i found in the hepl file & it worked just fine.

However. i have no idea why but even after i pause the script (I want to talk in MSn for example) i cant use the keys i used as shortcuts, basically it wont let u press lowercase c nor m until i exit prog.

SO hire is it .. was pretty simple actyally...

;theoretically the script should work only in this active window.....Practically it works in any active window for some reason....
WinWaitActive("Active window name hire")
$Equipment = HotKeySet("c", "equipment")  ;Hotkey to open equipment, (declaring c) & setting "equipment" as finction name
$map = HotKeySet("m", "map")     ;Hotkey to open map 
$Exitprogram = HotKeySet("^!z", "MyExit") ;LCTRL+ALT+Z Hotkey to exit program 

While 1              ;    This while just must be hire, dont ask me why it wont work without it!
    Sleep(10)
WEnd

Func equipment()    ;"equipment" function starts
    select
case $Equipment ; if c is pressed 
    Send("^w") ; sends LeftCtrl+w    
EndSelect
EndFunc     ;"equipment" function Ends

Func map()
    select
case $map ; if m is pressed 
    Send("^m") ; sends LeftCtrl+m   
EndSelect
EndFunc

Func MyExit() ; Function to exit script starts
    select
case $Exitprogram ; if LCTRL+ALT+Z is pressed
    Exit          ; Exits program
EndSelect
EndFunc
Link to comment
Share on other sites

I have written the script for you. please take the time to read the comments to understand why the loop is there and why you dont need select in your functions, you also dont need to assign HotKeySet() to a variable i.e.

$map = HotKeySet("m", "map")

I hope you enjoy using Autoit as much as I do once you get going

HotKeySet("^!z", "MyExit") ;set hotkey to exit before going to infinte loop

While 1 ;this loop needs to be here because it is the main part of the program which will keep checking if the window is active
    sleep(100); this is just here so that it checks it every 100 milliseconds instead of continously
    
    if  WinActive ( "Window title" )  then 
        HotKeySet("m", "map")       ;register hotkey if window is active
        HotKeySet("c", "equipment")
    Else
        HotKeySet("m") ;unregister hotkey if window not active
        HotKeySet("c")
    EndIf
WEnd

;you dont need "select" in these functions since it will only do these if its hotkey is pressed.

Func equipment()    ;"equipment" function starts
    Send("^w") ; sends LeftCtrl+w   
EndFunc     ;"equipment" function Ends

Func map()
    Send("^m") ; sends LeftCtrl+m   
EndFunc

Func MyExit() ; Function to exit script starts
    Exit          ; Exits program
EndFunc
Link to comment
Share on other sites

humm yes I understand but There is 1 problem I cant figure out why cant i use: F1-F12 keys or numpad keys or space or page down nor ctrl+ combintations ?

If i use a letter it works.. now this is a mystery, so is it possible for those keys also to work only in that selected window only?

if  WinActive ( "Window name" )  then 
        HotKeySet("F9", "skill_GET_Windbeads_PЬlayer") ;register hotkey if window is active
    Else
        HotKeySet("F9")  ;unregister hotkey if window not active
    EndIf
WEnd
;GET SKILLS BEGIN
;----------------------------------------------------------------
Func skill_GET_Windbeads_CHIEi()
    Send("^s")
    MouseClickDrag("right", 692, 185, 517, 733, 4)
    MouseMove(612, 341, 1)
    MouseClick("Left")
EndFunc
Edited by chie
Link to comment
Share on other sites

for f1-f12 use "{F1}" format.

You mean to make it like this? well this is the problem, its not working.

if  WinActive ( "Window name" )  then 
        Hotkeyset("{F8}", "skill_GET_Windbeads_CHIEi") ;register hotkey if window is active
    Else
       Hotkeyset("{F8}")  ;unregister hotkey if window not active
    EndIf
WEnd
;GET SKILLS BEGIN
;----------------------------------------------------------------
Func skill_GET_Windbeads_CHIEi()
    Send("^s")
    MouseClickDrag("right", 692, 185, 517, 733, 4)
    MouseMove(612, 341, 1)
    MouseClick("Left")
EndFunc
Link to comment
Share on other sites

Add some traces in your code to make sure it does as you intend it to :lmao:

Since you are a SciTe user type cw and hit CTRL+b.

Link to comment
Share on other sites

I guess you wanted something like this:

HotKeySet("{DEL}", "_Quit")

While 1
    If WinActive("window name") Then
        HotKeySet("{F8}", "skill_GET_Windbeads_CHIEi")
        Sleep(40)
    Else
        HotKeySet("{F8}"); ungregistered hotkey if window is not active.
        Sleep(40)
    EndIf
WEnd

;GET SKILLS BEGIN

Func skill_GET_Windbeads_CHIEi()
    Send("^s")
    MouseClickDrag("right", 692, 185, 517, 733, 4)
    MouseMove(612, 341, 1)
    MouseClick("Left")
EndFunc

Func _Quit()
    If WinExists("window name") Then
        WinClose("window name")
        Sleep(40)
        Exit
    Else
        Exit
    EndIf
EndFunc

I always add sleep() in the end of the Loops because of the CPU usage :lmao:

Edited by AceLoc

[quote name='AceLoc']I gots new sunglasses there cool.[/quote]

Link to comment
Share on other sites

I guess you wanted something like this:

I really thank u for trying to help me but this is not the thing i dont understand. In your script all it does is: if u press DEL key it will exit prog ( & it does not mahter, if the window is active or not. )

to put it simply:

I want to use the keys only in the specified window, because if i change the window & start typing something it wont let me use those keys(basically script will perform its operations in a wrong window if i press in your EXAPLE DEL key!)

To avoid this,next code was used, but if the DEL key for example was tried to declare like this the script showed no error but it did not work eather:

While 1 ;this loop needs to be here because it is the main part of the program which will keep checking if the window is active
    sleep(100); this is just here so that it checks it every 100 milliseconds instead of continously
    
    if  WinActive ( "Window title" )  then 
        HotKeySet("m", "map")      ;register hotkey if window is active
    Else
        HotKeySet("m") ;unregister hotkey if window not active
    EndIf
WEnd

Func map()
    Send("^m") ; sends LeftCtrl+m   
EndFunc
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...