RStudio refuses AutoHotkeys - (...why?)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
asderad
Posts: 8
Joined: 17 Mar 2021, 15:41

RStudio refuses AutoHotkeys - (...why?)

28 Jul 2021, 07:20

Dear members of the community,

If anyone of you is familiar with "RStudio" at all (R, programming language IDE) -

Is it normal that the software disables all AutoHotkeys once open ?

Only concerns the window itself too, switching to anything else and my layout works just fine.
(some of my A-Hkeys even crash the program altogether, eg. language switching)


Anyhow,
I would greatly appreciate any insights you guys might have on the matter.

Cheerios -
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: RStudio refuses AutoHotkeys - (...why?)

28 Jul 2021, 07:35

Sounds like a permissions issue - probably RStudio runs with elevated rights.
See https://www.autohotkey.com/docs/FAQ.htm#uac

The language switching problem might be completely unrelated.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: RStudio refuses AutoHotkeys - (...why?)

28 Jul 2021, 08:06

or installs keyboard hooks on top of ahk's(and possibly removes them once the window is no longer active)

show the script
asderad
Posts: 8
Joined: 17 Mar 2021, 15:41

Re: RStudio refuses AutoHotkeys - (...why?)

28 Jul 2021, 13:00

swagfag wrote:
28 Jul 2021, 08:06
or installs keyboard hooks on top of ahk's(and possibly removes them once the window is no longer active)

show the script
Thanks for your fast reply -
What are keyboard "hooks" ?

Here's the script (sorry for the mess)

_________________________________________________________________________________________________

Code: Select all

#If GetKeyState("CapsLock", "T")
j::Numpad1
k::Numpad2
l::Numpad3
u::Numpad4
i::Numpad5
o::Numpad6
7::Numpad7
8::Numpad8
9::Numpad9
,::Numpad0
0::+
p::-
SC027::*
.::=
m::,

w::up
a::left
s::down
d::right
r::pgup
f::pgdn

q:: send {LWin down}{LCtrl down}{Left}{LCtrl up}{LWin up}  
e:: send {LWin down}{LCtrl down}{Right}{LCtrl up}{LWin up}
SC056:: send {LCtrl down}{a down}{a up}{LCtrl up}
x:: send {LCtrl down}{x down}{x up}{LCtrl up}
c:: send {LCtrl down}{c down}{c up}{LCtrl up}
v:: send {LCtrl down}{v down}{v up}{LCtrl up}
z:: send {LCtrl down}{z down}{z up}{LCtrl up}
y:: send {LCtrl down}{y down}{y up}{LCtrl up}

SC029:: SetDefaultKeyboardLang(0x0407) ; german
1:: SetDefaultKeyboardLang(0x02809)  ; english
2:: SetDefaultKeyboardLang(0x040C) ; french
3:: SetDefaultKeyboardLang(0x0804) ; chinese
SetDefaultKeyboardLang(LocaleID){
	Static SPI_SETDEFAULTINPUTLANG := 0x005A, SPIF_SENDWININICHANGE := 2	
	Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
	VarSetCapacity(binaryLocaleID, 4, 0)
	NumPut(LocaleID, binaryLocaleID)
	DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", &binaryLocaleID, "UInt", SPIF_SENDWININICHANGE)	
	WinGet, windows, List
	Loop % windows {
		PostMessage 0x50, 0, % Lan, , % "ahk_id " windows%A_Index%
	}
}
 


;#If GetKeyState("CapsLock", "T")
;x::
;c::
;v::
;Send ^%A_ThisHotkey%
;SetCapsLockState, Off
;Return
;\::
;Send ^a
;SetCapsLockState, Off
;Return
[Mod edit: [code][/code] tags added.]

_______________________________________________________________________________________________________-
asderad
Posts: 8
Joined: 17 Mar 2021, 15:41

Re: RStudio refuses AutoHotkeys - (...why?)

28 Jul 2021, 13:03

gregster wrote:
28 Jul 2021, 07:35
Sounds like a permissions issue - probably RStudio runs with elevated rights.
See https://www.autohotkey.com/docs/FAQ.htm#uac

The language switching problem might be completely unrelated.
Hey, thank you for your reply -
Hm, well RStudio does run with administrator rights on in order to function properly.

Is there a way to sidestep this permissions issue ?
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: RStudio refuses AutoHotkeys - (...why?)

28 Jul 2021, 13:07

asderad wrote:
28 Jul 2021, 13:03
Is there a way to sidestep this permissions issue ?
Without giving AHK sufficient rights (which could be the 'Run with UI Access' option) ?
I don't think so. It's a Windows security feature.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: RStudio refuses AutoHotkeys - (...why?)

28 Jul 2021, 13:56

if ure interested in the technical nitty gritty, ull need some Windows background. there are resources out there that explain it far better than i ever could or would bother to
instead ill give u a shitty analogy:
  • an announcer(Windows) monitors whats going on around him
  • there's a bunch of people(ur script and other programs) neatly queued in front of him
  • when something interesting happens(such as physically depressing a key on a keyboard), he writes it down on a piece of paper and passes it to the first person in front of him
  • uve collectively agreed(hopefully) to read whats on the paper and once ure done reading it, behave and pass the paper along to the next person behind u
  • in comes an uncultured swine(RStudio), muscling through the entire queue and plants himself in front of the announcer
  • expectedly, he receives the piece of paper, reads it and throws it away. why did he do this? did he not know he was supposed to pass it along? did he simply not care enough to do so? was it a purposefully malicious action? whatever the reason, it is usually not interesting(u could figure it out but thats getting way too involved). he got to read his paper, whereas u didnt even get the chance to
asderad
Posts: 8
Joined: 17 Mar 2021, 15:41

Re: RStudio refuses AutoHotkeys - (...why?)

28 Jul 2021, 13:59

gregster wrote:
28 Jul 2021, 13:07
asderad wrote:
28 Jul 2021, 13:03
Is there a way to sidestep this permissions issue ?
Without giving AHK sufficient rights (which could be the 'Run with UI Access' option) ?
I don't think so. It's a Windows security feature.
Oh I always just assumed that AHK ran on top of everything by default, so I should launch it with administrator rights on ?

- Where could I find the "run with UI access option" ?
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: RStudio refuses AutoHotkeys - (...why?)

28 Jul 2021, 14:01

Not necessarily admin rights, if you can avoid it - for the UI access option follow the FAQ link I posted above.
peter2108
Posts: 5
Joined: 11 Dec 2021, 06:06

Re: RStudio refuses AutoHotkeys - (...why?)

11 Dec 2021, 06:15

asderad wrote:
28 Jul 2021, 07:20
Dear members of the community,

If anyone of you is familiar with "RStudio" at all (R, programming language IDE) -

Is it normal that the software disables all AutoHotkeys once open ?

Only concerns the window itself too, switching to anything else and my layout works just fine.
(some of my A-Hkeys even crash the program altogether, eg. language switching)


Anyhow,
I would greatly appreciate any insights you guys might have on the matter.

Cheerios -
I use RStudio with Autohotkeys with some success but my scripts are simple.

Code: Select all

#If WinActive("ahk_class Qt5QWindowIcon ahk_exe rstudio.exe")
!4:: Send, !tg
!5:: Send, {Down}{Tab 18}{Enter}
#If
The first key opens the tools menu global option. The second key operates in the dialog to open the snippets menu.
However, if I try

Code: Select all

!4:: Send, !tg{Down}{Tab 18}{Enter}
it stops at 'g' I expect this is just my not knowing AutoHotKeys well.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Theda and 172 guests