Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem setting focus on first form element after GUI is generated #15

Open
oyhel opened this issue Aug 25, 2021 · 3 comments
Open

Problem setting focus on first form element after GUI is generated #15

oyhel opened this issue Aug 25, 2021 · 3 comments

Comments

@oyhel
Copy link

oyhel commented Aug 25, 2021

First of all, huge thanks for your work! This has helped me immensely with quickly getting survey forms up in a clinical setting, filling out and pasting the resulting info.

However, one issue I am struggling with is that forms are not receiving focus after the GUI/Neutron app appears. I have to physically click the window with the Neutron app and the click tab in order for the cursor be positioned in the form (5 radio groups with 5 elements each) forcing me to use the mouse initially instead of keyboard only.

I have tried to play around with

WinActivate, neutron.ahk ; activating the window with the Neutron app
Sleep, 200
ControlClick, X170 Y170, neutron.ahk ; to send that needed click
Send, {tab} ; to get the cursor positioned

However a) it does not seem to work when code is placed within the app (as part of launching of the Neutron app) and it is also a bit brittle.

Is it possible to force focus on first form elements in a more elegant way?

@SaifAqqad
Copy link
Contributor

SaifAqqad commented Aug 25, 2021

I use neutron.doc.focus() to focus the document, but it also works if you want to focus a specific form element.
MDN Element.focus()

But you may also need to focus the window immediately after showing it, which you can do more reliably with

WinActivate, % "ahk_id " neutron.hWnd

Also both of these should be after the neutron.Show() call

@oyhel
Copy link
Author

oyhel commented Aug 25, 2021

Thank you very much for the quick reply!

I added after neutron.Show()

neutron.Show()
neutron.doc.focus()
WinActivate, % "neutron.ahk" neutron.hWnd
Send, {tab}
;WinActivate, neutron.ahk
return

...and it worked as intended, setting focus to the first radio group!
Thanks again!

@SaifAqqad
Copy link
Contributor

You actually don't even need the Send, {tab}, you can just set an id for the radio group (ex. "radio_group") and do neutron.doc.getElementById("radio_group").focus()

and you also don't need the window name in WinActivate, just give it the hWnd WinActivate, % "ahk_id " neutron.hWnd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants