Problem with hotkeys and IBeam cursor condition

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
usser
Posts: 146
Joined: 22 Oct 2014, 13:03

Problem with hotkeys and IBeam cursor condition

29 Feb 2024, 15:57

Hello

I am severely struggling with an issue for years now. So I have set up these AHK hotkeys to basically go to the previous/next tab in Chrome:
1::^PgUp
2::^PgDn

I also have this condition:
A_cursor!="IBeam"

However, the hotkeys do not work as intended. Particularly, when the cursor is IBeam but the focus is not in a text input control, the hotkeys should still work (but they don't with the above code).

Is there any workaround to this?

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

Re: Problem with hotkeys and IBeam cursor condition

29 Feb 2024, 18:22

So just to clarify, although you didn't state it this way, you really don't want the condition to be based on the cursor being an IBeam at all. You just want it to be based on whether the focus is on a text input control or not. I don't know how to do that, but maybe someone else can offer a solution. I suspect it would be difficult because of how various applications handle text input "controls".
User avatar
kunkel321
Posts: 1137
Joined: 30 Nov 2015, 21:19

Re: Problem with hotkeys and IBeam cursor condition

29 Feb 2024, 18:37

I have a boilerplate text entry tool I use in webforms, so I've tried over and over to reliably determine if an edit field is active in Chrome. I've never found a good way. Though.... As I type this reply, it occurs to me that the edit box has a white background, whereas Boiler's (non editable) text in the above post has a light blue background... I wonder if that would be a reliable way to check(?)

EDIT: Maybe you can do something with these pieces of code(??)
I'm not sure how you would use this in a #HotIf directive though...

Code: Select all

#SingleInstance
#Requires AutoHotkey v2+
mouseX := ''
mouseY := ''
MouseGetPos &mouseX, &mouseY  ; Get the current mouse position
color := PixelGetColor(mouseX, mouseY)  ; Get the color of the pixel at the mouse's position
If (A_cursor!="IBeam") || (color != 0xFFFFFF)
ste(phen|ve) kunkel
usser
Posts: 146
Joined: 22 Oct 2014, 13:03

Re: Problem with hotkeys and IBeam cursor condition

01 Mar 2024, 06:36

Thanks, that could be a good potential strategy but unfortunately I don't think it will be robust because there will be numerous webpages with non editable text where the background colour is white.
The cursor over such text will be IBeam but also the cursor would not be inside a text input control so it should still trigger the hotkey.

What would be ideal is to have two conditions for the hotkey to work:
1) cursor is IBeam
AND
2) there is a focus in an text input control maybe determined by the blinking IBeam that appears inside text input controls? is that possible?
User avatar
kunkel321
Posts: 1137
Joined: 30 Nov 2015, 21:19

Re: Problem with hotkeys and IBeam cursor condition

01 Mar 2024, 09:22

It's actually the Caret that blinks, rather than the cursor. The difference made me think to try this:

Code: Select all

#SingleInstance
#Requires AutoHotkey v2+
#+q::
{	CaretGetPos(&cX, &cY)
	msgbox 'x ' cX '`ny ' cY
}
The idea was that if no caret pos was returned, it meant no blinking caret
But the blasted thing doesn't seem to work in web edit fields! :evil:

Here also is a chunk of code that I was using with my above-mentioned boilerplate tool..

Code: Select all

	;Check for active edit field.
	ThisSec := SubStr(A_Sec, -1)
	Send ThisSec "+{Left}" ; Type the single digit, then select it.
	Send '^x' ; Cut to clipboard.
	Sleep 500
	If (Trim(A_Clipboard,"`n`r ") != ThisSec) ; Compare, to see if item was typed/copied. 
It types a "random" digit, then selects, and cuts the digit to the clipboard and checks to see if the clipboard contains the digit. If there's no active edit box, then for digit doesn't get typed, and so doesn't appear on the clipboard.

It's a really kludgy and awkward thing thing though. So bad that I stopped using it.

If a person was an HTML wizard they might have some ideas too. I don't know anything about HTML though. Also, as I think, Boiler pointed out, different website might have different code, so relying on HTML stuff might be unreliable too.

EDIT: Actually... Here are better testable versions of the above things. The "compare to clipboard" one actually does work really well in webforms. I don't know that it will be a good solution for you though, since your hotkeys (1 and 2) are also things that would get typed. You wouldn't want this whole bit of code running every time you typed a 1 or 2.

Code: Select all

#SingleInstance
#Requires AutoHotkey v2+

#+w::
{
;Check for active edit field.
ThisSec := SubStr(A_Sec, -1)
Send "{Right} " ThisSec "+{Left}" ; Type the single digit, then select it.
Send '^x' ; Cut to clipboard.
Sleep 200
If (Trim(A_Clipboard,"`n`r ") != ThisSec) ; Compare, to see if item was typed/copied. 
	Msgbox 'No active edit box'
Else
	Msgbox 'Yes active edit box'
}

#+q::msgbox 'car? ' CaretGetPos() 
My advice is to use a modifier with your hotkeys. For example ^1:: and ^2::.
ste(phen|ve) kunkel
usser
Posts: 146
Joined: 22 Oct 2014, 13:03

Re: Problem with hotkeys and IBeam cursor condition

01 Mar 2024, 16:51

That's great thanks! It seems quite clunky as you said though :/
Maybe an AHK develop can advise why the first option does not work with web edit fields and maybe even fix it?
That would really be ideal.
User avatar
kunkel321
Posts: 1137
Joined: 30 Nov 2015, 21:19

Re: Problem with hotkeys and IBeam cursor condition

05 Mar 2024, 08:44

FYI I found an old thread where I was researching this topic: viewtopic.php?f=76&t=91100&p=402569&hilit=edit+field#p402569

I didn't (and still don't) really understand ACC enough to run with the code, but maybe it will be useful for you. Also, this was all v1 stuff, so you'd need to find v2 versions of the tools.
ste(phen|ve) kunkel
usser
Posts: 146
Joined: 22 Oct 2014, 13:03

Re: Problem with hotkeys and IBeam cursor condition

12 Mar 2024, 14:40

Brilliant thank you! I will be diving into these asap.

By the way, I found out that I can make the Blinking Caret whatever colour I want via Windows settings. I was thinking if I can colour it with a colour that is extremely rare, I could then have AHK detect that colour on the screen as a condition for the hotkey to work?

Any thoughts?

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: wilkster and 40 guests