Changing values when button pressed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yasinlemouv
Posts: 1
Joined: 21 Sep 2017, 15:31

Changing values when button pressed

21 Sep 2017, 15:40

So i was wondering if anyone could help me with this:

Code: Select all

mouseXY(0, 0)
So i want to change the second coordinate(Y), so when i press for example f1 it changes the value to 1, when i press f2 it changes the value to 2 and if i press f3 it changes the value to 3 etc.

If there is anyone who could help me out eith this i would greatly appreciate it

Kind regards,
Yasin
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Changing values when button pressed

21 Sep 2017, 15:45

Code: Select all

F10::MouseXY(0,SubStr(A_ThisHotkey,2))
Not tested.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Changing values when button pressed

21 Sep 2017, 16:41

Hi Yasinlemouv,

Welcome to the AHK community.

Here's two solutions:

1. the hard-code way (which Bobo probably had in mind but confused speed with haste ;) ):

Code: Select all

F1::
F2::
F3::
F4::
F5::
F6::
F7::
F8::
F9::
F10::
F11::
F12::
MouseXY(0, LTrim(A_ThisHotkey, "F")) ; calls MouseXY (pass as second parameter the name of the most recently executed hotkey "A_ThisHotkey" trimming "F"  from the beginning of the string)
return


mouseXY(__x, __y) {
MsgBox % __x . "," . __y ; for example
}

2. More complicated, using a BoundFunc Object:

Code: Select all

Loop % 12
{
f := Func("mouseXY").bind(0, a_index) ; creates a func object and binds it predefined parameters so that when the func object is called, it calls the function passing it automatically any bound parameters
Hotkey % "F" . a_index, % f ; set the hotkey using the hotkey command which allows us use variables and set the boundfunc object as label
}
return ; end of the auto-execute section


mouseXY(__x, __y) {
MsgBox % __x . "," . __y ; for example
}

; see also: https://www.autohotkey.com/docs/objects/Func.htm
	    ; https://www.autohotkey.com/docs/commands/Hotkey.htm
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Holarctic, ishida20, jameswrightesq, Lem2001 and 403 guests