Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Autohotkey & RWin


  • Please log in to reply
4 replies to this topic
Balbes
  • Guests
  • Last active:
  • Joined: --
Autohotkey glitches with Rwin buttons. Ex:
AppsKey::
{
	SetFormat, Integer, H
	Locale1=0x4090409  ; Английский (американский).
	Locale2=0x4190419  ; Русский.
	WinGet, WinID,, A
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)
	if(InputLocaleID=Locale1)
		SendMessage, 0x50,, % Locale2,, A
	else if(InputLocaleID=Locale2)
		SendMessage, 0x50,, % Locale1,, A
}

RWin::
{
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1
	SetFormat, Integer, H
	Locale1=0x4090409  ; Английский (американский).
	Locale2=0x4190419  ; Русский.
	WinGet, WinID,, A
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)
	if(InputLocaleID=Locale1)
	{
		SendMessage, 0x50,, % Locale2,, A
		KeyWait, RWin
		SendMessage, 0x50,, % Locale1,, A
	}
	else
	{
		SendMessage, 0x50,, % Locale1,, A
		KeyWait, RWin
		SendMessage, 0x50,, % Locale2,, A
	}
	Send {RWin UP}
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0
}
And:
RWin::
{
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1
	SetFormat, Integer, H
	Locale1=0x4090409  ; Английский (американский).
	Locale2=0x4190419  ; Русский.
	WinGet, WinID,, A
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)
	if(InputLocaleID=Locale1)
	{
		SendMessage, 0x50,, % Locale2,, A
		KeyWait, RWin
		SendMessage, 0x50,, % Locale1,, A
	}
	else
	{
		SendMessage, 0x50,, % Locale1,, A
		KeyWait, RWin
		SendMessage, 0x50,, % Locale2,, A
	}
	Send {RWin UP}
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0
}

AppsKey::
{
	SetFormat, Integer, H
	Locale1=0x4090409  ; Английский (американский).
	Locale2=0x4190419  ; Русский.
	WinGet, WinID,, A
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)
	if(InputLocaleID=Locale1)
		SendMessage, 0x50,, % Locale2,, A
	else if(InputLocaleID=Locale2)
		SendMessage, 0x50,, % Locale1,, A
}
Isn't equal. Basically, it switches language between rus and eng. AppsKey just switches, and RWin switches on down and switches back on up. Yet first script works, and second doesn't. Second script switches language on RWin Down, but don't switches it back on RWin Up.
The second problem is damn Win+L. I've disabled Lock. But, now script doesn't recognize RWin+L at all. So I've added a hook on RWin+L to force it printing L char. This hook works well:
RWin & L::
{
	SetFormat, Integer, H
	Locale1=0x4090409  ; Английский (американский).
	Locale2=0x4190419  ; Русский.
	WinGet, WinID,, A
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)
	if(InputLocaleID=Locale1)
	{
		Send {ASC 108}
	}
	else
	{
		Send {ASC 164}
	}
}
But! When I putting both RWin:: and RWin & L:: hooks in one script, RWin:: doesn't works. Like this:
AppsKey::
{
	SetFormat, Integer, H
	Locale1=0x4090409  ; Английский (американский).
	Locale2=0x4190419  ; Русский.
	WinGet, WinID,, A
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)
	if(InputLocaleID=Locale1)
		SendMessage, 0x50,, % Locale2,, A
	else if(InputLocaleID=Locale2)
		SendMessage, 0x50,, % Locale1,, A
}
RWin::
{
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1
	SetFormat, Integer, H
	Locale1=0x4090409  ; Английский (американский).
	Locale2=0x4190419  ; Русский.
	WinGet, WinID,, A
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)
	if(InputLocaleID=Locale1)
	{
		SendMessage, 0x50,, % Locale2,, A
		KeyWait, RWin
		SendMessage, 0x50,, % Locale1,, A
	}
	else
	{
		SendMessage, 0x50,, % Locale1,, A
		KeyWait, RWin
		SendMessage, 0x50,, % Locale2,, A
	}
	Send {RWin UP}
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0
}

RWin & L::
{
	SetFormat, Integer, H
	Locale1=0x4090409  ; Английский (американский).
	Locale2=0x4190419  ; Русский.
	WinGet, WinID,, A
	ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
	InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)
	if(InputLocaleID=Locale1)
	{
		Send {ASC 108}
	}
	else
	{
		Send {ASC 164}
	}
}
No matter in what order I putting this hooks

Balbes
  • Guests
  • Last active:
  • Joined: --
Forget to mention - I'm using win7 x64

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Braces have no effect with hotkeys. You need to terminate your hotkeys with Return or Exit. In your examples, pressing any hotkey will execute the code for that hotkey and every hotkey after it.

Using RWin:: as a hotkey will block RWin keystrokes, thus preventing it from triggering any Win+key combinations. This is expected behaviour.

Using RWin & L:: as a hotkey will cause RWin:: to execute only when RWin is released, and only if no other keys were pressed in combination with RWin (such as RWin+L or RWin+D). This is expected behaviour.

joric
  • Members
  • 1 posts
  • Last active: Aug 07 2015 10:57 AM
  • Joined: 28 Apr 2015

There's something wrong with autorepeat, e.g. I mapped this on Windows 8:

 

RWin::RCtrl
^[::Send {Volume_Down}
^]::Send {Volume_Up}

And there's no autorepeat when I press RWin+[, it works only for the first stroke then starts printing [. When I press LCtrl+[ it works fine. Is it a bug?



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
The problem is due to the way remapping works:

When a script is launched, each remapping is translated into a pair of hotkeys. For example, a script containing a::b actually contains the following two hotkeys instead:

*a::
SetKeyDelay -1 ; If the destination key is a mouse button, SetMouseDelay is used instead.
Send {Blind}{b DownTemp} ; DownTemp is like Down except that other Send commands in the script won't assume "b" should stay down during their Send.
return

*a up::
SetKeyDelay -1 ; See note below for why press-duration is not specified with either of these SetKeyDelays.
Send {Blind}{b Up}
return
Source: Remapping Keys and Buttons


Send {Volume_Down} implicitly means to send that key unmodified, i.e. without RCtrl held down. If you Send {RCtrl Down} first, the Send command knows you want that key held down, so doesn't release it. Since most remappings probably aren't intended to affect the Send command that way, they use DownTemp. However, while this causes Send to automatically release RCtrl, it does not automatically press RCtrl back down afterward.

There are a few workarounds:
  • Send {Blind}{Volume_Up} - Blind prevents modifier keys from automatically being released. This effectively means the command will produce Ctrl+Volume_Up, which usually works.
  • Split the remapping and hotkeys which use it into separate scripts. That way, Send {Volume_Up} will not be aware that Send was used to press RCtrl, so it will automatically press the RCtrl key back down after it has sent Volume_Up.
  • Use the registry remapping method.