Problem with making a GUI button press translate to a key press loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Tactical Shrimp
Posts: 31
Joined: 11 Nov 2015, 22:29

Problem with making a GUI button press translate to a key press loop

29 Jan 2017, 21:21

Alright so I have a script with a couple different functions for a remote control project and i have a GUI set up so that you may press button for a few predetermined actions here it is

Code: Select all

; GLOBAL SETTINGS ===============================================================================================================

#singleInstance, force
#Persistent
;#IfWinActive ahk_class RC Link (Stage) x64

movement = 0

; GUI ===========================================================================================================================

Gui, Margin, 50, 50
Gui, Add, Button, xm y+5 w70 gBUTTON_Forward, % "Forward"
Gui, Add, Button, xm y+5 w70 gBUTTON_Circle, % "Circle"
Gui, Add, Button, xm y+5 w70 gBUTTON_Halt, % "Suspend"
Gui, Add, Button, xm y+5 w70 gBUTTON_Stop, % "pause"
Gui, Add, Button, xm y+5 w70 gBUTTON_Aim, % "Aim"
Gui, Add, Button, xm y+5 w70 gBUTTON_CLOSE, % "CLOSE"
Gui, Show, AutoSize
return

; SCRIPT ========================================================================================================================



BUTTON_Forward:
	movement = 1
return

BUTTON_Circle:
	movement = 2
return

BUTTON_Halt:
	movement = 3
return

Button_Stop:
	movement = 0
return

BUTTON_Aim:
	MsgBox unimplemented
return

BUTTON_CLOSE:
    ExitApp
return

; Function ======================================================================================================================

if(movement == 0)
{
    return
}

else if(movement == 1)
{
    sendinput, w
}

else if(movement == 2)
{
    sendinput, wd
}

else if(movement == 0)
{
    sendinput, g
	sleep 100
}

; Class =========================================================================================================================
; EXIT ==========================================================================================================================

GuiClose:
GuiEscape:
ExitApp
so as you can see i have a variable movement and many buttons that should change this variable and these changes should activate an else if function. However when i press these buttons nothing happens i even tested it with a blank text file and nothing.

Regards a very tactile shrimp
ManualColdLock
Posts: 175
Joined: 15 Dec 2016, 04:27

Re: Problem with making a GUI button press translate to a key press loop

30 Jan 2017, 02:32

See if this helps at all

Code: Select all

Gui, Margin, 50, 50
Gui, Add, Button, xm y+5 w70, Forward
Gui, Add, Button, xm y+5 w70 , Circle
Gui, Add, Button, xm y+5 w70 , Suspend
Gui, Add, Button, xm y+5 w70 , Pause
Gui, Add, Button, xm y+5 w70,CLOSE
Gui, Show, AutoSize
return

Buttonclose:
GuiEscape:
GuiClose:
Exitapp

ButtonForward:
msgbox, You Pressed Forward!
return

ButtonCircle:
Msgbox, Functions aren't necessary for what your script currently does. You can just put "sendinput, w" right here instead of msgbox
return

ButtonSuspend:
msgbox, If you put "Sendmode, Input" at the top of your script you can just use send instead.
run,  https://autohotkey.com/docs/commands/SendMode.htm
return

ButtonPause:
; This does nothing
return
Tactical Shrimp
Posts: 31
Joined: 11 Nov 2015, 22:29

Re: Problem with making a GUI button press translate to a key press loop

30 Jan 2017, 21:20

this did not seam to work eather and i have retired to a simple keypress but thanks for the help cheers

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy, Rohwedder and 401 guests