Issue with Win + Arrow Key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zLynde
Posts: 4
Joined: 18 Feb 2019, 00:02

Issue with Win + Arrow Key

18 Feb 2019, 00:10

TL;DR
This script sends Win + Arrow twice, instead of once...
So I've got my modifier keys remapped in Autohotkey, and I have kind of a weird want for the right control key. I basically want it to function as an alt key, except when an arrow key is pressed in addition to the RAlt key, in which case I want it to send the corresponding WIn+Arrow command. I've got it basically working, but with a really annoying problem: When holding the right Ctrl Key, the first press of an arrow key functions perfectly, resizing or snapping the window according to the OS's basic functionality, but on subsequent presses of the arrow key, the window seems to change as if I held the windows key and pressed that arrow key twice. I've been tweaking this for a couple hours now, but I'm too new at AHK to spot the problem in my code.

Thanks all, reading these forums has helped me a ton in getting my scripts working, so any help you can provide here is much appreciated.

Code: Select all

RCtrl::
	SendInput {RAlt Down}
	Loop
	{
	if GetKeyState("Up")
		{
		SendInput {RAlt Up}
		SendInput {RWin Down}{Up Down}{Up Up}
		Keywait, Up
		continue
		}
	if GetKeyState("Down")
		{
		SendInput {RAlt Up}
		SendInput {RWin Down}{Down Down}{Down Up}
		Keywait, Down
		continue
		}
	if GetKeyState("Left")
		{
		SendInput {RAlt Up}
		SendInput {RWin Down}{Left Down}{Right Up}
		Keywait, Left
		continue
		}
	if GetKeyState("Right")
		{
		SendInput {RAlt Up}
		SendInput {RWin Down}{Right Down}{Right Up}
		Keywait, Right
		continue
		}
	if GetKeyState("RCtrl", "P") = 0
		{
		Send {vk07}{RWin Up}{RAlt Up}
		break
		}
	}
	return
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Issue with Win + Arrow Key

18 Feb 2019, 08:50

You only send RWin Up when you release RCtrl - that might be an issue for the following key presses.
i have been unable to achieve any effect using your script - so I sadly cannot help you any further with this script.
Recommends AHK Studio
zLynde
Posts: 4
Joined: 18 Feb 2019, 00:02

Re: Issue with Win + Arrow Key

18 Feb 2019, 10:15

nnnik wrote:
18 Feb 2019, 08:50
You only send RWin Up when you release RCtrl - that might be an issue for the following key presses.
i have been unable to achieve any effect using your script - so I sadly cannot help you any further with this script.
Thanks for trying. That's an interesting thought. The problem is that if I send RWin Up anywhere else in the process, Windows thinks I'm done and does that annoying animation where it asks what window you want in the "void". So if I move the window multiple times, I have to wait for that animation each and every move throughout the process.
zLynde
Posts: 4
Joined: 18 Feb 2019, 00:02

Re: Issue with Win + Arrow Key

18 Feb 2019, 15:50

I figured it out!
The problem was indeed the fact that the winkey wasn't released, or more accurately, that the winkey was sent again whenever an arrow key was pressed. To fix it, I had to create a subroutine (which is completely new to me, but seems to be working) that the first loop handed off to after an arrow key was pressed. (the first loop could handle the first Win+Arrow press before handing off, since it didn't have any problems with that.)
The second loop is very similar to the first loop, but it doesn't send the winkey down input, or the alt up command, since they should still be down from the first loop.

Leaving the code here in case anyone finds it useful.
I also added tooltips so I could see what was happening.

Code: Select all

	
RCtrl::
	SendInput {RAlt Down}
	ToolTip, Waiting for arrow
	Loop ; Continuously checks for an arrow key to be pressed, then sends to WinArrow Loop
	{
	if GetKeyState("Up", "P")
		{
		SendInput {RAlt Up}
		SendInput {RWin Down}{Up Down}{Up Up}
		Keywait, Up
		Gosub, WinArrow
		break
		}
	if GetKeyState("Down", "P")
		{
		SendInput {RAlt Up}
		SendInput {RWin Down}{Down Down}{Down Up}
		Keywait, Down
		Gosub, WinArrow
		break
		}
	if GetKeyState("Left", "P")
		{
		SendInput {RAlt Up}
		SendInput {RWin Down}{Left Down}{Left Up}
		Keywait, Left
		Gosub, WinArrow
		break
		}
	if GetKeyState("Right", "P")
		{
		SendInput {RAlt Up}
		SendInput {RWin Down}{Right Down}{Right Up}
		Keywait, Right
		Gosub, WinArrow
		break
		}
	if GetKeyState("RCtrl", "P") = 0
		{
		SendInput {vk07}{RWin Up}{RAlt Up}
		break
		}
	}
	ToolTip
	return
	
WinArrow:
	ToolTip, WinArrow Running
	Loop
	{
	if GetKeyState("Up", "P")
		{
		SendInput {Up}
		Keywait, Up
		continue
		}
	if GetKeyState("Down", "P")
		{
		SendInput {Down}
		Keywait, Down
		continue
		}
	if GetKeyState("Left", "P")
		{
		SendInput {Left}
		Keywait, Left
		continue
		}
	if GetKeyState("Right", "P")
		{
		SendInput {Right}
		Keywait, Right
		continue
		}
	if GetKeystate("RCtrl", "P") = 0
		{
		SendInput {RWin Up}{RAlt Up}
		break
		}
	}
	ToolTip
	return
	

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Decar, doodles333, mikeyww and 223 guests