Order of pressing modifier keys affects the result

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
victorv
Posts: 26
Joined: 31 Dec 2018, 09:13

Order of pressing modifier keys affects the result

31 Dec 2018, 09:43

I am using this code to make Win + Right act like End. And Shift + Win + Right to act as Shift + End:

Code: Select all

LWin & Right::
;    ss := GetKeyState("Shift")
;    ToolTip %ss%
	if GetKeyState("Shift") = 1
		Send +{End}
	Else 
		Send {End}
Return
If I press first Shift then Win then Right, the cursor moves to the end of line selecting the text.
But if I first press Win and then Shift then Right -- the text is not selected.
Is this the expected behaviour?
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: Order of pressing modifier keys affects the result

10 Jan 2019, 13:12

Your hotkey works fine for me when I test it on text in the text box on this website and in Notepad. It also works when I change the keypress order as you describe. I suspect that this is not an AHK issue.

My hotkey code:

Code: Select all

LWin & Right::
if	GetKeyState("SHIFT")
	Send +{END}
else	Send {END}
return
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Order of pressing modifier keys affects the result

10 Jan 2019, 13:31

.
Last edited by IMEime on 13 Jan 2019, 19:12, edited 1 time in total.
victorv
Posts: 26
Joined: 31 Dec 2018, 09:13

Re: Order of pressing modifier keys affects the result

11 Jan 2019, 01:45

Here is my full script:

Code: Select all

LWin & Left::
	GetKeyState, state, Shift
	If state = D
		Send +{Home}
	Else Send {Home}
Return

LWin & Right::
	if GetKeyState("Shift") = 1
		Send +{End}
	Else 
		Send {End}
Return

LWin & Up::
	if GetKeyState("Shift") = 1
		Send +{PgUp}
	Else 
		Send {PgUp}
Return

LWin & Down::
	if GetKeyState("Shift") = 1
		Send +{PgDn}
	Else 
		Send {PgDn}
Return

LShift & BackSpace::
	Send {Del}
return

LWin up::
return

LWin::
return

Shift & LWin::
return

LWin & Shift::
return


Alt & Space::
	Send #{Space}
return
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Order of pressing modifier keys affects the result

11 Jan 2019, 02:30

.
Last edited by IMEime on 13 Jan 2019, 19:12, edited 1 time in total.
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Order of pressing modifier keys affects the result

11 Jan 2019, 03:25

For Get State try using: GetKeyState("Shift", "P"). Works for me!
victorv
Posts: 26
Joined: 31 Dec 2018, 09:13

Re: Order of pressing modifier keys affects the result

11 Jan 2019, 04:56

rommmcek wrote:
11 Jan 2019, 03:25
For Get State try using: GetKeyState("Shift", "P"). Works for me!
This helps, but then the default Win behaviour is triggered -- Start menu is opened. Can this be avoided?
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: Order of pressing modifier keys affects the result

11 Jan 2019, 09:07

Exit all of your other running scripts, create a brand new script that contains just this hotkey:

Code: Select all

LWin & Right::
if	GetKeyState("SHIFT")
	Send +{END}
else	Send {END}
return
Run just the new script and try to execute the hotkey. What happens?
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Order of pressing modifier keys affects the result

11 Jan 2019, 10:22

To prevent Start Menu I use Keywait, LWin before return. Listen to other members too!
victorv
Posts: 26
Joined: 31 Dec 2018, 09:13

Re: Order of pressing modifier keys affects the result

12 Jan 2019, 12:05

sinkfaze wrote:
11 Jan 2019, 09:07
Exit all of your other running scripts, create a brand new script that contains just this hotkey:

Code: Select all

LWin & Right::
if	GetKeyState("SHIFT")
	Send +{END}
else	Send {END}
return
Run just the new script and try to execute the hotkey. What happens?
In both cases (first pressing Shift, then Win and first pressing Win then Shift) it works, except that the Start menu is opened after that.
victorv
Posts: 26
Joined: 31 Dec 2018, 09:13

Re: Order of pressing modifier keys affects the result

12 Jan 2019, 12:09

rommmcek wrote:
11 Jan 2019, 10:22
To prevent Start Menu I use Keywait, LWin before return. Listen to other members too!
Tried with only this code in the whole script:

Code: Select all

LWin & Right::
	if	GetKeyState("SHIFT")
		Send +{END}
	else	Send {END}
	Keywait, LWin
return
Didn't help. When I press just Win and Right it goes to the end of the line, no matter if Keywait command is present. When I use Shift -- the Start menu is opened in both cases.
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Order of pressing modifier keys affects the result

12 Jan 2019, 12:53

Two things:
- you forgot to include "physical" parameter.
- did you close all other AutoHotkey scripts?

P.s:: For me it works w/o problems.
victorv
Posts: 26
Joined: 31 Dec 2018, 09:13

Re: Order of pressing modifier keys affects the result

12 Jan 2019, 15:31

rommmcek wrote:
12 Jan 2019, 12:53
Two things:
- you forgot to include "physical" parameter.
- did you close all other AutoHotkey scripts?

P.s:: For me it works w/o problems.

"P" makes not difference for this simple script.
I have only one file. Editing it and reloading in SciTE4AutoHotkey.

I have no idea why it works for you. AutoHotkey version? Windows version?
I am using the latest Windows 10 with AutoHotkey v1.1.30.01

Code: Select all

001: Return (4.72)
002: if GetKeyState("SHIFT", "P")  
003: Send,+{END} (0.02)
005: KeyWait,LWin (0.28)
006: Return (2.95)
002: if GetKeyState("SHIFT", "P")  
003: Send,+{END} (0.03)
005: KeyWait,LWin (0.19)
006: Return (3.20)
002: if GetKeyState("SHIFT", "P")  
003: Send,+{END} (0.03)
005: KeyWait,LWin (0.22)
006: Return (3.36)
002: if GetKeyState("SHIFT", "P")  
003: Send,+{END} (0.03)
005: KeyWait,LWin (0.45)
006: Return (2.31)
002: if GetKeyState("SHIFT", "P")  
003: Send,+{END} (0.02)
005: KeyWait,LWin (0.20)
006: Return (2.75)
002: if GetKeyState("SHIFT", "P")  
003: Send,+{END} (0.03)
005: KeyWait,LWin (0.11)
006: Return (22.27)
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Order of pressing modifier keys affects the result

12 Jan 2019, 16:28

This is discouraging!
Try (Note first line #NoEnv):

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

LWin & Right::
;~ #Right::
	if	GetKeyState("SHIFT", "P")
		Send +{END}
	else	Send {END}
	Keywait, LWin
	Keywait, Shift
return
Try with #Right:: too!
If you didn't already, consider restart OS running as less apps as possible.
Run the script from Explorer, Run or Command line. Not from Sci4Ahk via F5 or ^+F5.

P.s.: My OS Win10 updated Oct 2018 or so, Ahk v1.1.29.01
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Order of pressing modifier keys affects the result

14 Jan 2019, 11:27

Try running the script as admin!
Namely I just got feedback it might do the trick.
victorv
Posts: 26
Joined: 31 Dec 2018, 09:13

Re: Order of pressing modifier keys affects the result

15 Jan 2019, 04:22

I decided to switch to `Alt + Arrow` instead of using Win key. It works. Will see if any app uses Alt + Arrow for its purposes and it is inconvenient for me.

Thank you for your help!
victorv
Posts: 26
Joined: 31 Dec 2018, 09:13

Re: Order of pressing modifier keys affects the result

15 Jan 2019, 04:54

I started SciTE4AutoHotkey as administrator then started the script from there. The behaviour is the same.
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Order of pressing modifier keys affects the result

15 Jan 2019, 06:18

Beware! Win OS cache does sometimes strange things e.g. running app from memory which content is not necessarily the same as the one on the HD! So for testing while developing, starting the script form command line is very useful!
P.s.: Alt + Arrow in browser and explorer is Back and Forward respectively.
victorv
Posts: 26
Joined: 31 Dec 2018, 09:13

Re: Order of pressing modifier keys affects the result

15 Jan 2019, 10:10

Yes, it was a bad idea for Alt to be used for this purpose.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Ardalion, marypoppins_1 and 55 guests