Compiled exe behaves diff than source??

Get help with using AutoHotkey and its commands and hotkeys
Skrell
Posts: 166
Joined: 23 Jan 2014, 12:05

Compiled exe behaves diff than source??

13 Sep 2015, 15:56

The code i wrote below was meant to allow the user to drag a window left <-> right and up <-> down easily by grabbing the edge of a window. When i run just the ahk file it works PERFECTLY; however, if i compile the script i find that upon releasing the RButton that the script CONTINUES to lock the mouse in 1-dimension and never releases it until i click on a different window. Any ideas what could cause this??

Code: Select all

$RButton::
  MouseGetPos, mx_r, my_r, hWin
  WinGetPos, winX, winY, winW, winH, ahk_id %hWin%
  oldmx := mx_r, oldmy := my_r
  
  BlockInput, on
  If (IsOverResizableLeftBorder(mx_r,my_r, hWin)=1)
  {
    If (mx_r < 0) {
        height       := mon2height+adjustment
        width        := mon2width
        right_coord  := -1
        left_coord   := MonitorWorkArea2Left
		top_coord    := mon2top-adjustment
        bottom_coord := MonitorWorkArea2Bottom
    }
    else {
        height       := mon1height+adjustment
        width        := mon1width
        right_coord  := mon1width-1 
        left_coord   := 0
		top_coord    := mon1top-adjustment
        bottom_coord := MonitorWorkArea1Bottom
    }
    SetTimer, MoveHorizontalLeft, 20
  }
  else if  (IsOverResizableRightBorder(mx_r,my_r, hWin)=1)
  {
    If (mx_r < 0) {
        height       := mon2height+adjustment
        width        := mon2width
        right_coord  := -1
        left_coord   := MonitorWorkArea2Left
		top_coord    := mon2top-adjustment
        bottom_coord := MonitorWorkArea2Bottom
    }
    else {
        height       := mon1height+adjustment
        width        := mon1width
        right_coord  := mon1width-1 
        left_coord   := 0
		top_coord    := mon1top-adjustment
        bottom_coord := MonitorWorkArea1Bottom
    }
    SetTimer, MoveHorizontalRight, 20
  }
  else if ((IsOverResizableTopBorder(mx_r,my_r, hWin)=1 || IsOverResizableBottomBorder(mx_r,my_r, hWin)=1))
  {
    If (mx_r < 0) {
        height       := mon2height+adjustment
        width        := mon2width
        right_coord  := -1
        left_coord   := MonitorWorkArea2Left
		top_coord    := mon2top-adjustment
        bottom_coord := MonitorWorkArea2Bottom
    }
    else {
        height       := mon1height+adjustment
        width        := mon1width
        right_coord  := mon1width-1 
        left_coord   := 0
		top_coord    := mon1top-adjustment
        bottom_coord := MonitorWorkArea1Bottom
    }
    SetTimer, MoveVertical, 20
  }
  BlockInput, off
  Send {RButton down}
  KeyWait,  RButton
  SetTimer, MoveHorizontalLeft, off
  SetTimer, MoveHorizontalRight, off
  SetTimer, MoveVertical, off
  Send {RButton up}
  DllCall("ClipCursor")
  deltax := 0
  deltay := 0
Return
 
 MoveHorizontalLeft:
    MouseGetPos, mx_r, my_r
    WinGetPos, winX, winY, winW, winH, ahk_id %hWin%
    deltax := mx_r - oldmx
    winX_new := winX + deltax
    if (oldmx <> mx_r)
    {
        Confine(1,left_coord,my_r,right_coord-10,my_r)
        WinMove, ahk_id %hWin%, , winX_new,
    }
    oldmx := mx_r
 Return
 
 MoveHorizontalRight:
    MouseGetPos, mx_r, my_r
    WinGetPos, winX, winY, winW, winH, ahk_id %hWin%
    deltax := mx_r - oldmx
    winX_new := winX + deltax
    if (oldmx <> mx_r)
    {
        Confine(1,left_coord+10,my_r,right_coord,my_r)
        WinMove, ahk_id %hWin%, , winX_new,
    }
    oldmx := mx_r
 Return
 
 MoveVertical:
    MouseGetPos, mx_r, my_r
    WinGetPos, winX, winY, winW, winH, ahk_id %hWin%
    deltay := my_r - oldmy
    winY_new := winY + deltay
    if (oldmy <> my_r)
    {
        Confine(1,mx_r,top_coord,mx_r,bottom_coord)
        WinMove, ahk_id %hWin%, , , winY_new
    }
    oldmy := my_r
 Return
 
 Confine(C=0,X1=0,Y1=0,X2=0,Y2=0){
  VarSetCapacity(R,16,0),NumPut(X1,&R+0),NumPut(Y1,&R+4),NumPut(X2,&R+8),NumPut(Y2,&R+12)
  Return C ? DllCall("ClipCursor",UInt,&R) : DllCall("ClipCursor")
}
 
lexikos
Posts: 6960
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Compiled exe behaves diff than source??

13 Sep 2015, 20:48

Is the .bin file you are compiling with the same version of AutoHotkey?

If in doubt,

Code: Select all

MsgBox % A_AhkVersion " " (A_IsUnicode ? "Unicode " : "ANSI ") (A_PtrSize*8 "-bit")
Skrell
Posts: 166
Joined: 23 Jan 2014, 12:05

Re: Compiled exe behaves diff than source??

13 Sep 2015, 21:06

lexikos wrote:Is the .bin file you are compiling with the same version of AutoHotkey?

If in doubt,

Code: Select all

MsgBox % A_AhkVersion " " (A_IsUnicode ? "Unicode " : "ANSI ") (A_PtrSize*8 "-bit")
Yep.
Skrell
Posts: 166
Joined: 23 Jan 2014, 12:05

Re: Compiled exe behaves diff than source??

13 Sep 2015, 21:19

Here is a compilable version:
Also note that i'm using this on 32bit XP and it doesn't seem to happen on my Win8.1 machine....

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
#MaxHotkeysPerInterval 200

;SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, Mouse, Screen
SetBatchLines, -1
SetWinDelay, 0
ListLines, Off
; Set the script's priority as high (not really necessary)
Process, Priority, , AboveNormal

SysGet, MonitorWorkArea1, MonitorWorkArea, 1
    mon1height := MonitorWorkArea1Bottom-MonitorWorkArea1Top
    mon1width  := MonitorWorkArea1Right-MonitorWorkArea1Left
	mon1top    := MonitorWorkArea1Top
SysGet, MonitorWorkArea2, MonitorWorkArea, 2
    mon2height := MonitorWorkArea2Bottom
    mon2width  := -MonitorWorkArea2Left
	mon2top    := MonitorWorkArea2Top
$RButton::
  MouseGetPos, mx_r, my_r, hWin
  WinGetPos, winX, winY, winW, winH, ahk_id %hWin%
  oldmx := mx_r, oldmy := my_r
 
  BlockInput, on
  If (IsOverResizableLeftBorder(mx_r,my_r, hWin)=1)
  {
    If (mx_r < 0) {
        height       := mon2height+adjustment
        width        := mon2width
        right_coord  := -1
        left_coord   := MonitorWorkArea2Left
		top_coord    := mon2top-adjustment
        bottom_coord := MonitorWorkArea2Bottom
    }
    else {
        height       := mon1height+adjustment
        width        := mon1width
        right_coord  := mon1width-1 
        left_coord   := 0
		top_coord    := mon1top-adjustment
        bottom_coord := MonitorWorkArea1Bottom
    }
    SetTimer, MoveHorizontalLeft, 20
  }
  else if  (IsOverResizableRightBorder(mx_r,my_r, hWin)=1)
  {
    If (mx_r < 0) {
        height       := mon2height+adjustment
        width        := mon2width
        right_coord  := -1
        left_coord   := MonitorWorkArea2Left
		top_coord    := mon2top-adjustment
        bottom_coord := MonitorWorkArea2Bottom
    }
    else {
        height       := mon1height+adjustment
        width        := mon1width
        right_coord  := mon1width-1 
        left_coord   := 0
		top_coord    := mon1top-adjustment
        bottom_coord := MonitorWorkArea1Bottom
    }
    SetTimer, MoveHorizontalRight, 20
  }
  else if ((IsOverResizableTopBorder(mx_r,my_r, hWin)=1 || IsOverResizableBottomBorder(mx_r,my_r, hWin)=1))
  {
    If (mx_r < 0) {
        height       := mon2height+adjustment
        width        := mon2width
        right_coord  := -1
        left_coord   := MonitorWorkArea2Left
		top_coord    := mon2top-adjustment
        bottom_coord := MonitorWorkArea2Bottom
    }
    else {
        height       := mon1height+adjustment
        width        := mon1width
        right_coord  := mon1width-1 
        left_coord   := 0
		top_coord    := mon1top-adjustment
        bottom_coord := MonitorWorkArea1Bottom
    }
    SetTimer, MoveVertical, 20
  }
  BlockInput, off
  Send {RButton down}
  KeyWait,  RButton
  SetTimer, MoveHorizontalLeft, off
  SetTimer, MoveHorizontalRight, off
  SetTimer, MoveVertical, off
  Send {RButton up}
  DllCall("ClipCursor")
  deltax := 0
  deltay := 0
Return
 
 MoveHorizontalLeft:
    MouseGetPos, mx_r, my_r
    WinGetPos, winX, winY, winW, winH, ahk_id %hWin%
    deltax := mx_r - oldmx
    winX_new := winX + deltax
    if (oldmx <> mx_r)
    {
        Confine(1,left_coord,my_r,right_coord-10,my_r)
        WinMove, ahk_id %hWin%, , winX_new,
    }
    oldmx := mx_r
 Return
 
 MoveHorizontalRight:
    MouseGetPos, mx_r, my_r
    WinGetPos, winX, winY, winW, winH, ahk_id %hWin%
    deltax := mx_r - oldmx
    winX_new := winX + deltax
    if (oldmx <> mx_r)
    {
        Confine(1,left_coord+10,my_r,right_coord,my_r)
        WinMove, ahk_id %hWin%, , winX_new,
    }
    oldmx := mx_r
 Return
 
 MoveVertical:
    MouseGetPos, mx_r, my_r
    WinGetPos, winX, winY, winW, winH, ahk_id %hWin%
    deltay := my_r - oldmy
    winY_new := winY + deltay
    if (oldmy <> my_r)
    {
        Confine(1,mx_r,top_coord,mx_r,bottom_coord)
        WinMove, ahk_id %hWin%, , , winY_new
    }
    oldmy := my_r
 Return
 
 Confine(C=0,X1=0,Y1=0,X2=0,Y2=0){
  VarSetCapacity(R,16,0),NumPut(X1,&R+0),NumPut(Y1,&R+4),NumPut(X2,&R+8),NumPut(Y2,&R+12)
  Return C ? DllCall("ClipCursor",UInt,&R) : DllCall("ClipCursor")
}

IsOverResizableBottomRightBorder(x, y, hWnd)
{
	SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
	return (ErrorLevel == 17)
}
; ------------------------------------------------------------------------------

IsOverResizableBottomLeftBorder(x, y, hWnd)
{
	SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
	return (ErrorLevel == 16)
}
; ------------------------------------------------------------------------------

IsOverResizableLeftBorder(x, y, hWnd)
{
	SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
	return (ErrorLevel == 10)
}
; ------------------------------------------------------------------------------

IsOverResizableRightBorder(x, y, hWnd){
	SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
	return (ErrorLevel == 11)
}
; ------------------------------------------------------------------------------

IsOverResizableTopBorder(x, y, hWnd){
	SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
	return (ErrorLevel == 12)
}
; ------------------------------------------------------------------------------

IsOverResizableBottomBorder(x, y, hWnd){
	SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
	return (ErrorLevel == 15)
}
lexikos
Posts: 6960
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Compiled exe behaves diff than source??

13 Sep 2015, 21:35

The problem is simply that you are calling ClipCursor incorrectly.

Code: Select all

DllCall("ClipCursor")
MsgBox % ErrorLevel  ; A-4 (when run on 32-bit)
DllCall("ClipCursor", "ptr", 0)
MsgBox % ErrorLevel  ; 0
You cannot omit parameters in a DllCall unless the function is specifically designed to take a variable number of parameters (like printf). "Optional" parameters are usually implemented accepting a NULL/zero value. In this case MSDN specifically states "If this parameter is NULL, the cursor is free to move anywhere on the screen."

If you specify too few parameters, the function will take whatever it finds on the stack. What it gets depends on the platform (32-bit or 64-bit) and other factors you have no control over (like luck).
Skrell
Posts: 166
Joined: 23 Jan 2014, 12:05

Re: Compiled exe behaves diff than source??

13 Sep 2015, 21:42

THANK YOU SO SO SO MUCH! I never would have figured this out!!!!! <3

Return to “Ask For Help”

Who is online

Users browsing this forum: 2ndprotocol, Bing [Bot], Chunjee, frosse, malcev, navmesh, Zamfir and 53 guests