Cycle through input form fields using same key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Cycle through input form fields using same key

17 Jun 2021, 09:26

Hi,

Our work is still old school and predominantly setting up new customers over the phone.

I wish to use the same hotkey to cycle through various fields, type the info...then press same key again to get to next relevant field.
New customer setup.JPG
New customer setup.JPG (50.07 KiB) Viewed 598 times
  • Company Name
  • Contact name
  • Telephone
  • Email 1
i know how to get to these individually using co-ordinates or classnn but not for the same hotkey. Obvs no way around the manual typing.

Many Thanks
Gareth
User avatar
boiler
Posts: 17070
Joined: 21 Dec 2014, 02:44

Re: Cycle through input form fields using same key

17 Jun 2021, 10:19

I see you know how to get the control names, so you would just need to use ControlFocus using control names that you would have stored in an array, and increment an index variable to use the next value in the array each time you press the hotkey.
User avatar
boiler
Posts: 17070
Joined: 21 Dec 2014, 02:44

Re: Cycle through input form fields using same key

17 Jun 2021, 10:27

(re-read the above post after this one appears because it was edited with more relevant direction)
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Cycle through input form fields using same key

17 Jun 2021, 10:39

Hi boiler,

Thanks for the response.
Overall windo info.JPG
Overall window titles etc
Overall windo info.JPG (42.83 KiB) Viewed 573 times
Company Name Edit3

Contact name Edit15

Telephone Edit17

Email 1 Edit27

Also, which I didn't post in my orig post, the question mark button doesn't return a control name. I wish for this to be clicked last (it launches a postcode lookup addon).

Many Thanks
User avatar
boiler
Posts: 17070
Joined: 21 Dec 2014, 02:44

Re: Cycle through input form fields using same key

17 Jun 2021, 10:46

gazmoz17 wrote: the question mark button doesn't return a control name. I wish for this to be clicked last (it launches a postcode lookup addon).
Is that true even if you enable the “Follow Mouse” option of the Window Spy tool and hover over that button?
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Cycle through input form fields using same key

17 Jun 2021, 10:51

Argh...sorry I thought I had that enabled by default (used to).

ClassNN: WindowsForms10.BUTTON.app.0.3553390_r30_ad11
Text: ?
x: 437 y: 351 w: 20 h: 20
User avatar
boiler
Posts: 17070
Joined: 21 Dec 2014, 02:44

Re: Cycle through input form fields using same key

17 Jun 2021, 12:35

See if this script works. Use F1 to cycle through the controls, clicking on the "?" button when it gets to that control (hopefully). F2 resets the index in case you need to. Use Ctrl+Esc to exit the script. Of course, you can change the hotkeys to whatever you want.

Code: Select all

WinTitle := "Customer Record ahk_class #32770 ahk_exe SBDDesktop.exe"
Controls := ["Edit3", "Edit15", "Edit17", "Edit27", "WindowsForms10.BUTTON.app.0.3553390_r30_ad11"]
Index := 0

F1::
	Index := Index = 5 ? 1 : Index + 1
	ControlFocus, % ThisCtrl := Controls[Index], % WinTitle
	if InStr(ThisCtrl, "WindowsForms")
		ControlClick, % ThisCtrl, % WinTitle
return

F2::Index := 0

^Esc::ExitApp
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Cycle through input form fields using same key

18 Jun 2021, 02:35

Hi Boiler,

Just tested this in work now and it works great :D . Thank you very much.

I'm going to have a go adding a few other controls as well.

Cheers
Gareth
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Cycle through input form fields using same key

18 Jun 2021, 04:44

Hi,

Struggling to add another button. The "address and contacts" button below the "?" button.

In your code is the 5 in the below the total number of controls/buttons?
Index := Index = 5 ? 1 : Index + 1

From that logic(which might be wrong :D ) I've tried the below (changing to 6) but its not working.

Code: Select all

WinTitle := "Customer Record ahk_class #32770 ahk_exe SBDDesktop.exe"
Controls := ["Edit3", "Edit15", "Edit17", "Edit27", "WindowsForms10.BUTTON.app.0.3553390_r30_ad11", "Button6"]
Index := 0

F6::
	Index := Index = 6 ? 1 : Index + 1
	ControlFocus, % ThisCtrl := Controls[Index], % WinTitle
	if InStr(ThisCtrl, "WindowsForms")
		ControlClick, % ThisCtrl, % WinTitle
return

F2::Index := 0

^Esc::ExitApp

Think its to do with the button I'm trying to click because code works with 6 for diff button eg Tel 2= Edit 18

Also not sure if below is correct (to test that button names firing correct per window spy)

Code: Select all

#ifWinactive, Customer Record ahk_class #32770 ahk_exe SBDDesktop.exe
^m::
ControlClick,Button6, Customer Record 
Return
#ifWinactive
The above control click doesnt seem to work for any button?

Thanks
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Cycle through input form fields using same key

18 Jun 2021, 06:53

Assuming Address & Contacts button ClassNN is Button6.
Try this:

Code: Select all

WinTitle := "Customer Record ahk_class #32770 ahk_exe SBDDesktop.exe"
Controls := ["Edit3", "Edit15", "Edit17", "Edit27", "WindowsForms10.BUTTON.app.0.3553390_r30_ad11", "Button6"]
Index := 0

F1::
	Index := Index = 6 ? 1 : Index + 1
	ControlFocus, % ThisCtrl := Controls[Index], % WinTitle
	if InStr(ThisCtrl, "WindowsForms") || (ThisCtrl = "Button6")
		ControlClick, % ThisCtrl, % WinTitle
return

F2::Index := 0

^Esc::ExitApp
User avatar
boiler
Posts: 17070
Joined: 21 Dec 2014, 02:44

Re: Cycle through input form fields using same key

18 Jun 2021, 07:42

gazmoz17 wrote: Also not sure if below is correct (to test that button names firing correct per window spy)

Code: Select all

#ifWinactive, Customer Record ahk_class #32770 ahk_exe SBDDesktop.exe
^m::
ControlClick,Button6, Customer Record 
Return
#ifWinactive
The above control click doesnt seem to work for any button?
Are you saying the script I posted actually clicks the "?" button, but your above test script doesn't when you change to its ClassNN? Does the following click that button?

Code: Select all

#IfWinActive, Customer Record ahk_class #32770 ahk_exe SBDDesktop.exe
^m::
ControlFocus, WindowsForms10.BUTTON.app.0.3553390_r30_ad11, Customer Record  ahk_class #32770 ahk_exe SBDDesktop.exe
ControlClick, WindowsForms10.BUTTON.app.0.3553390_r30_ad11, Customer Record  ahk_class #32770 ahk_exe SBDDesktop.exe
Return
#IfWinActive
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Cycle through input form fields using same key

18 Jun 2021, 08:56

Hi,

Boiler: the last script youve just posted doesnt find the "?" button. Your first script worked perfectly and found the "?" button. Its just when Ive gone to add the "Address & Contacts" button it cant find it.

Smile: Hi thanks for the response. Your script sort of highlights the button (goes blue as though selected) but doesn't click it.

Thanks
User avatar
boiler
Posts: 17070
Joined: 21 Dec 2014, 02:44

Re: Cycle through input form fields using same key

18 Jun 2021, 09:08

gazmoz17 wrote: Boiler: the last script youve just posted doesnt find the "?" button. Your first script worked perfectly and found the "?" button. Its just when Ive gone to add the "Address & Contacts" button it cant find it.
I don’t know why that would be. Perhaps change the hotkey from Ctrl+M to F1 in case holding Ctrl down is somehow affecting it.

gazmoz17 wrote: Smile: Hi thanks for the response. Your script sort of highlights the button (goes blue as though selected) but doesn't click it.
Try replacing this line:

Code: Select all

ControlClick, % ThisCtrl, % WinTitle
...with this one:

Code: Select all

ControlSend, % ThisCtrl, {Enter}, % WinTitle
...and see if it helps.
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Cycle through input form fields using same key

18 Jun 2021, 09:46

So...Ive changed the code per your instruction to this:

Code: Select all


WinTitle := "Customer Record ahk_class #32770 ahk_exe SBDDesktop.exe"
Controls := ["Edit3", "Edit15", "Edit17", "Edit27", "WindowsForms10.BUTTON.app.0.3553390_r30_ad11", "Button6"]
Index := 0

F6::
	Index := Index = 6 ? 1 : Index + 1
	ControlFocus, % ThisCtrl := Controls[Index], % WinTitle
	if InStr(ThisCtrl, "WindowsForms") || (ThisCtrl = "Button6")
		ControlSend, % ThisCtrl, {Enter}, % WinTitle
return

F2::Index := 0

^Esc::ExitApp

;reload

#ifWinactive, TESTSCRIPT - Notepad
^s::
Send, {ctrl down}s{ctrl up}
Sleep, 200
Reload, C:\Users\john\Desktop\TESTSCRIPT.ahk
Return
#ifWinactive
Closed all other scripts for interfering.

1st time ran the above after edit: Highlighted "?" button but no longer clicked it. But then went on to click my "Address & Contacts" button correctly.

Ran the script again and this time & prev attempts:

Only highlights the "?" button, doesn't do anything for "Address & Contacts" at all now.

Thanks
User avatar
boiler
Posts: 17070
Joined: 21 Dec 2014, 02:44

Re: Cycle through input form fields using same key

18 Jun 2021, 10:08

I can’t say why it acts differently each time. You might check to see if the control names change during use, which happens with some applications.

Since it seems one control seems to respond better to ControlClick and the other receiving an {Enter}, try this version:

Code: Select all

WinTitle := "Customer Record ahk_class #32770 ahk_exe SBDDesktop.exe"
Controls := ["Edit3", "Edit15", "Edit17", "Edit27", "WindowsForms10.BUTTON.app.0.3553390_r30_ad11", "Button6"]
Index := 0

F6::
	Index := Index = 6 ? 1 : Index + 1
	ControlFocus, % ThisCtrl := Controls[Index], % WinTitle
	if InStr(ThisCtrl, "WindowsForms")
		ControlClick, % ThisCtrl, % WinTitle
	if (ThisCtrl = "Button6")
		ControlSend, % ThisCtrl, {Enter}, % WinTitle
return

F2::Index := 0

^Esc::ExitApp

;reload

#ifWinactive, TESTSCRIPT - Notepad
^s::
Send, {ctrl down}s{ctrl up}
Sleep, 200
Reload, C:\Users\john\Desktop\TESTSCRIPT.ahk
Return
#ifWinactive

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], labrint and 200 guests