1
votes

I need help with a script, i want it to only run while im holding down a key. Heres the script:

;If you use this, you have to use absolute screen coordinates.
CoordMode, Mouse, Screen

;Suppose a 100x100 px bounding box for your game inventory.
;Eg., from (500, 500) to (600, 600)
#if GetKeyState("joy5")
joy5:: MouseMove, 1771, 531
joy5 Up::MouseMove %oldx%,%oldy%
Numpad8::
{
    ;Get current Mouse coords
    MouseGetPos, xCurrent ,yCurrent

    ;Calculate future Mouse coords
    xMoved := xCurrent
    yMoved := yCurrent - 35

    ;Check if the future mouse postion will be
    ;below the top border of your bounding box, 
    ;aka still inside it, after it has moved.
    ;If so, proceed and move the mouse,
    ;otherwise do nothing.
MouseGetPos, CoordXRec, CoordYRec
        MouseMove, xMoved, yMoved


if(yMoved < 503 && yMoved > 350 && yMoved > 360){
MouseMove 1846, 166
}
if(yMoved < 145){
MouseMove, %CoordXRec%, %CoordYRec%, 0
}
if(yMoved < 718 && yMoved < 720 && yMoved > 680){
MouseMove 1771, 671
}
return  
}
Numpad5::
{
    ;Get current Mouse coords
    MouseGetPos, xCurrent ,yCurrent

    ;Calculate future Mouse coords
    xMoved := xCurrent
    yMoved := yCurrent +35

    ;Check if the future mouse postion will be
    ;below the top border of your bounding box, 
    ;aka still inside it, after it has moved.
    ;If so, proceed and move the mouse,
    ;otherwise do nothing.

        MouseMove, xMoved, yMoved

if(yMoved > 285 && yMoved < 360){
MouseMove 1773, 526
}
if(yMoved > 697 && yMoved < 715){
MouseMove 1772, 736
}
return
}
Numpad4::
{
    ;Get current Mouse coords
    MouseGetPos, xCurrent ,yCurrent

    ;Calculate future Mouse coords
    xMoved := xCurrent -40
    yMoved := yCurrent 

    ;Check if the future mouse postion will be
    ;below the top border of your bounding box, 
    ;aka still inside it, after it has moved.
    ;If so, proceed and move the mouse,
    ;otherwise do nothing.
    if (xMoved > 1740) {
        MouseMove, xMoved, yMoved
    }
return  
}
Numpad6::
{
    ;Get current Mouse coords
    MouseGetPos, xCurrent ,yCurrent

    ;Calculate future Mouse coords
    xMoved := xCurrent +40
    yMoved := yCurrent 

    ;Check if the future mouse postion will be
    ;below the top border of your bounding box, 
    ;aka still inside it, after it has moved.
    ;If so, proceed and move the mouse,
    ;otherwise do nothing.
    if (xMoved < 1917) {
        MouseMove, xMoved, yMoved
    }
return  
}

Basicly you control the mouse with WASD and theres some other functionality to it aswell but i want to make it so that you have to hold down a key in order to move. Thanks!

only move when holding down a key.

2
Your question is too ambiguous. Which key do you want to hold down? If it's shift/control/alt/Win, the answer is trivial (use a modifier like +s::).Jim U
Thanks for the response! I managed to make it work. I also made so that the mouse jumps to a specific position when pressing "U". Now i want to make so that it returns to the previous position when releasing "U". I cant seem to make it work :( Any help is appreciated!kinkingsu
U Up::MouseMove %oldx%,%oldy% see documentation for hotkeysJim U
I tried but it doesnt seem to work :/ Did i mention i'm a complete noob? :P I edited the code in the main post that's how it looks like now the key is (joy5). Thanks again!kinkingsu
See code in my answer. Tested on numpad-8. You have numpad and joystick features in your question. FYI, according to the hotkey documentation, UP doesn't work for joystick buttonsJim U

2 Answers

0
votes

Move mouse to 500,500 when Number-Pad-8 is pressed and NumLock is on. Return mouse to original location when key is released.

Numpad8::move()
Numpad8 UP::unmove()

move()
{
  global oldx,oldy
  MouseGetPos oldx,oldy
  MouseMove 500,500
}

unmove()
{
  global oldx,oldy
  MouseMove %oldx%,%oldy%
}
0
votes

To answer your original question (if the question changed so drastically, please open another one and finish this one):

You can dis/enable hotkeys dynamically, using the Hotkey-command. Assuming your masterkey is Space:

space:: ; this is a static hotkey definition
    hotkey, numpad8, moveMouse1 ; this is a dynamic hotkey definition
    hotkey, numpad6, moveMouse2
    ; etc
return

space up::
    hotkey, numpad8, OFF ; this is a dynamic hotkey removal
    hotkey, numpad6, OFF
    ; etc
return

moveMouse1: ; this is a label
    moveMouse 50, 100
    ; your actions
return

moveMouse2:
    ; ....
return