0
votes

I have created a game in Flash (actionscript 2.0), which requires the mouse to be locked to the center of the screen (like a first person shooter). It is possible to do that in AS3 with Flash 11.2, but not in AS2. Using AutoHotKey, I am able to do this, using this code:

while (0=0){
    MouseMove, 410, 302, 90 
    sleep 100
}

Esc::ExitApp

This works fine, but I don't want to require AutoHotKey for my users. Is there a way to convert that script into a standalone application (.exe), or create this program in another language? (The Flash game will not be launched from the web)

2
while (0=0) is kinda confusing since it simply evaluates to while (true)mikew
@user2079386, Please provide some feedback on the proposed solutions and if one of the answers was realy helpful, then please "Accept" that answer. Thank you!Robert Ilbrink

2 Answers

1
votes

Is there a way to convert that script into a standalone application (.exe) ?

If you have installed AHK normally, you should be able to right click the .ahk file and choose "Compile Script".

If that option is not there, you can alternatively look in your start menu for the "ahk2exe" compiler which will produce an .exe output of your script.

0
votes

Instead of using a fixed location, which might behave differently on other screen sizes, you could use WinGetPos and set the X-Y coordinates dynamically. To prevent a "frozen" mouse when users switch with Atl+Tab you can make the mouse lock only when your game is running by checking with IfWinActive. Instead of a loop with a 100 ms wait, I opted for a 100 ms timer to call the script, but using a loop or while would work just as well.

SetTitleMatchMode, 2
SetTimer, CheckWin, 100

CheckWin:
{
    IfWinActive, YourAppNameHere ; ONLY runs when Your App is Active
    {
        WinGetPos, XStart, YStart, Width, Height, YourAppNameHere ; Use AHK Window Spy
        XPos:=XStart+(Width/2)
        YPos:=YStart+(Height/2)
        MouseMove, %XPos%, %YPos%, 90 
        Return
    }
}

^F1:: ; Ctrl+F1 to stop the timer based loop
SetTimer, CheckWin, Off
Return

Here is another solution:

#SingleInstance Force
#installKeybdHook
#Persistent

Xbutton2:: ; Toggle fix mouse in Center
Confine := !Confine
ClipCursor( Confine, A_ScreenWidth/2, A_ScreenHeight/2, A_ScreenWidth/2, A_ScreenHeight/2 )
Return 

ClipCursor( Confine=True, x1=0 , y1=0, x2=1, y2=1 )
{ 
    VarSetCapacity(R,16,0),  NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12) 
    Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" ) 
}