Getting rid of the jump when control moves up - sample code Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Getting rid of the jump when control moves up - sample code

22 May 2018, 07:05

Notice when you click up, it first jumps down a bit, what am I not coding correct?

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui Add, Text, x171 y155 w120 h23 +0x200 Center vMoveText, Moving
Gui Add, Button, x372 y24 w80 h23 gMoveRight, Right
Gui Add, Button, x373 y50 w80 h23 gMoveUp, Up
Gui Add, Button, x373 y78 w80 h23 gResetTimer, Reset

Gui Show, w460 h360, Moving
Return

MoveRight:
controlgetpos, rightx, righty,,,Static1, Moving
settimer, movesteps, 40
return
movesteps:
rightx += 2
guicontrol, move, Static1, x%rightx% 
return

MoveUp:

controlgetpos, upx, upy,,,Static1, Moving
settimer, movestepsup, 40
return
movestepsup:
upy -=2
guicontrol, move, Static1, y%upy% 

return

ResetTimer:
settimer, movestepsup, Off
settimer, movesteps, Off
guicontrol, move, Static1, x171 y155
return


GuiEscape:
GuiClose:
    ExitApp
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Getting rid of the jump when control moves up - sample code

22 May 2018, 07:49

I isolated the code and I think this might be helpful in solving this. Notice how without any comment to move the control, every time you hit up if moves it down?

I tried playing with CoordMode, Pixel, Window and some other options, but failed to fix. What is causing this control to keep getting pushed down when you press up? I am telling it to move, but the y location is the same as the location it is now, it should not move. The documentation made me think that maybe its coordmode.

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui Add, Text, x171 y155 w120 h23 +0x200 Center vMoveText, Moving

Gui Add, Button, x373 y50 w80 h23 gMoveUp, Up
Gui Add, Button, x373 y78 w80 h23 gResetTimer, Reset

Gui Show, w460 h360, Moving
Return

MoveUp:
controlgetpos, upx, upy,,,Static1, Moving
guicontrol, move, Static1, y%upy%
return

ResetTimer:
guicontrol, move, Static1, x171 y155
return

GuiEscape:
GuiClose:
    ExitApp
OCP
Posts: 98
Joined: 28 Mar 2018, 19:28

Re: Getting rid of the jump when control moves up - sample code

22 May 2018, 07:49

could it be because of this negative value

upy -=2
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Getting rid of the jump when control moves up - sample code

22 May 2018, 08:32

OCP wrote:could it be because of this negative value

upy -=2
I should have been clearer that my goal is to get the text to go up gradually

doing -2 each time should start moving the text upwards, not first lowering it. The lower the Y axis number the higher it should go,
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Getting rid of the jump when control moves up - sample code

22 May 2018, 09:07

In this example, notice it won't even move with the -26

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui Add, Text, x171 y155 w120 h23 +0x200 Center vMoveText, Moving

Gui Add, Button, x373 y50 w80 h23 gMoveUp, Up
Gui Add, Button, x373 y78 w80 h23 gResetTimer, Reset

Gui Show, w460 h360, Moving
Return

MoveUp:
controlgetpos, upx, upy,,,Static1, Moving
upy -= 26 ; change to upy -= 27 and press up and u will see movement every time you click
guicontrol, move, Static1, y%upy%

return

ResetTimer:
guicontrol, move, Static1, x171 y155
return

GuiEscape:
GuiClose:
    ExitApp
OCP
Posts: 98
Joined: 28 Mar 2018, 19:28

Re: Getting rid of the jump when control moves up - sample code

22 May 2018, 09:20

i think you need another set of coordinates to say from where to start so from your x y having an xs+ ys+ or so

sorry if i am not more help full i am not sure how to implement this myself in this case aldo i use it a lot on offsetting things relative to my mouse i never looked into what there is for gui stuff in the same way

i can give you an small example how i get some splashtext to appear offset of my mouse perhaps this will give you an idea
mouseGetPos,mx,my
mx+=25
my-=15
Progress, cw000000 CTFFFFFF W150 ZX1 ZY1 x%mx% y%my% m b fs25 zh0,Canseled, , , Arial
Sleep 400
Progress, Off
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Getting rid of the jump when control moves up - sample code  Topic is solved

22 May 2018, 09:54

Don't mix Control... and GuiControl... commands for controls of your own GUI's if possible. The appropriate command to get a GUI control's position and size to be used by GuiControl, Move, ... is

Code: Select all

GuiControlGet, P, Pos, MoveText
MsgBox, X: %PX% - Y: %PY% - W: %PW% - H: %PH%
The coordinates used/retrieved by GuiControl... commands are always relative to the GUI's client area, whereas ControlGetPos retrieves coordinates relative to the window rectangle:
ControlGetPos wrote:These coordinates are relative to the target window's upper-left corner ...
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Getting rid of the jump when control moves up - sample code

22 May 2018, 10:14

just me wrote:Don't mix Control... and GuiControl... commands for controls of your own GUI's if possible. The appropriate command to get a GUI control's position and size to be used by GuiControl, Move, ... is

Code: Select all

GuiControlGet, P, Pos, MoveText
MsgBox, X: %PX% - Y: %PY% - W: %PW% - H: %PH%
The coordinates used/retrieved by GuiControl... commands are always relative to the GUI's client area, whereas ControlGetPos retrieves coordinates relative to the window rectangle:
ControlGetPos wrote:These coordinates are relative to the target window's upper-left corner ...
Thank you so much been many hours trying to figure this out.

Here is the results if anyone wonders

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui Add, Text, x171 y155 w120 h23 +0x200 Center vMoveText, Moving

Gui Add, Button, x373 y50 w80 h23 gMoveUp, Up
Gui Add, Button, x373 y78 w80 h23 gResetTimer, Reset

Gui Show, w460 h360, Moving
Return

MoveUp:
GuiControlGet, P, Pos, MoveText
settimer, movestepsup, 40
return
movestepsup:
py -= 2
guicontrol, move, Static1, y%py%

return

ResetTimer:
settimer, movestepsup, off
guicontrol, move, Static1, x171 y155
return

GuiEscape:
GuiClose:
    ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Lamron750, mikeyww and 218 guests