RealVNC Viewer: How to minimise window with AHK

Get help with using AutoHotkey and its commands and hotkeys
mm548320
Posts: 3
Joined: 23 Jan 2021, 11:20

RealVNC Viewer: How to minimise window with AHK

Post by mm548320 » 23 Jan 2021, 11:47

Hi all,

I am using RealVNC Viewer on my local Windows machine (the Client) to log into another Windows computer (the Server). I have installed AHK on the Client and on the Server. When using RealVNC Viewer, I'm running it in full screen mode.

What I'd like to achieve is being able to switch between the Client and the Server by clicking the side button of my mouse. Switching from the Client to the Server works fine, using the WinActivate function. But I'm struggling to write some code which successfully gets me from the Server back to the Client by minimising the RealVNC Viewer window. Without AHK there are 2 ways to do this:

First approach is: Press F8 to open the RealVNC context menu in the left top corner of screen, then press "N" to minimise the window.
For some reason sending the F8 key via AHK doesn't work. Either it doesn't send the key or it's not recognised by the RealVNC viewer. Below is the code I used. Any ideas how to fix it?

Code: Select all

;Left side mouse key: Switch to Client by minimising VNC Viewer
;My left side mouse button is recognised by Windows as ^#Tab, hence the event trigger below. The trigger itself works fine. I've tested it with MsgBox.
^#Tab::
Send, {F8}
Sleep, 1000
Send, {n}
MsgBox, "I can see this MsgBox"
Return

Second approach is: Move the mouse cursor to the very top of the screen so the RealVNC Viewer floating menu pops down, then click the "Exit full screen" button on that menu.

I tried using the MouseMove and Click functions to replicate the manual way of minising RealVNC Viewer but that didn't work either. The problem is that the screen position that I'd have to hover over is outside of the permitted vertical range, so even the 0 vertical position is not high enough to activate the floating menu.

Code: Select all

;Left side mouse key: Switch to Client by minimising VNC Viewer
;My left side mouse button is recognised by Windows as ^#Tab, hence the event trigger below. The trigger itself works fine. I've tested it with MsgBox.
^#Tab::
CoordMode, Mouse, Screen
MouseMove, 844, 0, 0
Sleep, 1000
Click, 844, 14
Return
Many thanks in advance for your suggestions.
User avatar
mikeyww
Posts: 5142
Joined: 09 Sep 2014, 18:38

Re: RealVNC Viewer: How to minimise window with AHK

Post by mikeyww » 23 Jan 2021, 11:58

You might be able to move to a negative coordinate. You could try moving the window so that it is not maximized.

Standard window menus can usually be activated by Alt+Space. I do not know whether the VNC program would try to pass that to the server, but you could try it. You could try to click on the icon for the window menu.

You might also try SendPlay, though it seems not to work on Windows 10. You can use the Send command to send a Click.

You could try the AltTab method to switch to a different client window.
mm548320
Posts: 3
Joined: 23 Jan 2021, 11:20

Re: RealVNC Viewer: How to minimise window with AHK

Post by mm548320 » 23 Jan 2021, 12:58

Many thansk mikeyww. All good suggestions, and I tried all of them, but I fear none worked in the end. I know it's a tricky one.
You might be able to move to a negative coordinate.
Tried it, but even when instructing a negative number the mouse cursor only goes to the "zero position".
You could try moving the window so that it is not maximized.
That would defeat the purpose, as I'm looking to run it in full screen mode. I think even if I wouldn't do that, the AHK running on the Server would still be restricted to operating the mouse cursor within that (now smaller) window.
Standard window menus can usually be activated by Alt+Space. I do not know whether the VNC program would try to pass that to the server, but you could try it. You could try to click on the icon for the window menu.
Alt+Space will open the windows context menu for the app (for example Windows Explorer) that is open within the RealVNC server window, unfortunately not the one of the RealVNC Viewer itself.
You might also try SendPlay, though it seems not to work on Windows 10.
Tried it, but same result as for Send, i.e. didn't go through.
You can use the Send command to send a Click.
It likely wouldn't solve the problem because I can't move the mouse cursor outside of the server window.
You could try the AltTab method to switch to a different client window.
When I manually press AltTab then I'll just see the Windows app selector within the RealVNC server window. It's not captured by the client, so not sure it would help.
User avatar
mikeyww
Posts: 5142
Joined: 09 Sep 2014, 18:38

Re: RealVNC Viewer: How to minimise window with AHK

Post by mikeyww » 23 Jan 2021, 18:54

Thank you for the follow-up! Sorry I was not of any help.

I did find an interesting related post, worth a look.

https://www.thegeekstuff.com/2016/03/alt-tab-autohotkey/
mm548320
Posts: 3
Joined: 23 Jan 2021, 11:20

Re: RealVNC Viewer: How to minimise window with AHK

Post by mm548320 » 24 Jan 2021, 17:40

Thanks again mikeyww for your advice. I tried the script that was posted on the page you suggested, but it didn't change the behaviour in any way.

I have now found the following solution which partially solves my problem. If I use a keyboard shortcut instead of a mouse click then it works. On my local machine (RealVNC Viewer Client) I have defined this shortcut. So by presssing Ctrl+F1 I can successfully get out of and minimise RealVNC Viewer.

Code: Select all

^F1::
Send {f8}
Send n
return
The reason why this works is because AHK on my local machine captures Ctrl+F1 and doesn't send it the active app within the RealVNC remote session.

I still haven't figured out how I can use my mouse side button to get out of RealVNC Viewer. The mouse driver of my Sandstrom S8M113 mouse is hardcoded to interpret a side button click as the ^#Tab:: key. But when clicking within the RealVN Viewer Client then the key is sent to the server and not the client. And I haven't yet found a way for my AHK instance that runs on the server to get out of RealVNC viewer (sending F8 and sending clicks all didn't work).
User avatar
mikeyww
Posts: 5142
Joined: 09 Sep 2014, 18:38

Re: RealVNC Viewer: How to minimise window with AHK

Post by mikeyww » 24 Jan 2021, 17:48

Good to know.

AHK hotkeys can trigger other hotkeys within a script. Perhaps your mouse button can trigger the ^F1 sequence if you have both hotkeys (well, probably not, but worth a try). Also see SendLevel.
Post Reply

Return to “Ask For Help”