Tie Mouse to location of keyboard (arrows / tab)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
RobbieWilkes
Posts: 14
Joined: 27 Feb 2018, 21:52

Tie Mouse to location of keyboard (arrows / tab)

13 Mar 2018, 22:37

I've written before, regarding my YouTubeTV (Chrome kiosk) MCE Remote Control script, and after further investigation, I've decided to experiment with going a different route for the browse screens.

Currently, I've tied the right / left / up / down buttons on the remote / keyboard to the mouse, so that hitting those buttons moves the mouse a designated number of pixels in the associated direction, fairly typical. This is working pretty well, but certain things, such as moving off the left / right side of the screen, are not automatic.

What I discovered, though, was that, by default, YouTubeTV works REALLY well with just the standard right and left keys and the TAB / Shift-Tab for Down / Up. So, I can tie the remote buttons to those keys with great success... except when I want to know location, or utilize a mouse function.

So, here's my question. Is there a way to determine where the keyboard location is on the screen? When I hit right / left or Tab / Shift-Tab, is there a value that is trackable / findable via AHK, and, if so, is there a way to tie the mouse to it somehow, so that, when the keys are hit, and move in the default direction, the mouse follows it... not vice versa? Am I just, due to my lack of experience and tunnel-vision, missing something simple?

Thanks for any suggestions.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Tie Mouse to location of keyboard (arrows / tab)

14 Mar 2018, 01:27

Code: Select all

#SingleInstance, Force

~Right::MouseMove(1)
~Left::MouseMove(1)
~Tab::MouseMove(8)
~+Tab::MouseMove(8)

MouseMove(px) {
    MouseGetPos, x, y
    x := If (A_ThisHotkey == "~Right") || (A_ThisHotkey == "~Tab") ? x + px : x - px
    If (x > A_ScreenWidth) || (x < 0) || (y > A_ScreenHeight) || (y < 0)
        Return
    MouseMove, x, y
    ToolTip % x . " : " . y . "`n" . A_ThisHotkey
    Return
    }
    
F12::ToolTip
Not tested.
User avatar
RobbieWilkes
Posts: 14
Joined: 27 Feb 2018, 21:52

Re: Tie Mouse to location of keyboard (arrows / tab)

15 Mar 2018, 15:44

BoBo wrote:Not tested.
Wow! You were just able to type that out? That's impressive!

I've played around with integrating it into my script, but, unfortunately, YouTube TV uses different sizes for the selections on random rows, so trying to establish a set mouse movement either right / left or up /down won't work. It's like they're trying to make it as difficult as possible.

I was excited to discover the A_CaretX and A_CaretY variables, but, then almost as quickly, sad to discover that they do not work in Chrome. ARGH!

It just seems that there MUST be some way to determine the location of the keyboard cursor, but I guess Chrome just decides to not allow it .

Thanks for your input BoBo! I'm continuing to learn a lot, with ever brick wall I run into. :headwall: <---- such an appropriate emoticon for scripting. :lol:
Guest

Re: Tie Mouse to location of keyboard (arrows / tab)

15 Mar 2018, 16:09

I think you'd find a lot of this easier if you tried something like Chrome.ahk: https://autohotkey.com/boards/viewtopic.php?f=6&t=42890

If you can connect to a Chrome instance displaying YouTube with it, you can have hotkeys wired up to run JavaScript in the context of the page, so you can simulate clicks by element name; or you can find out the ID of whatever element is currently selected and so on

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Exies, JoeWinograd, scriptor2016 and 100 guests