Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is visual studio catching key events before autohotkey?

I recently switched to the Dvorak keyboard layout as a bit of an experiment. One of the most difficult parts of the transition has been dealing with hot-keys. Most hot-keys are designed with QWERTY in mind and, to make matters worse, hot-keys seem to be extremely muscle memory bound.

Rather than relearn all the hot-keys, I've written an autohotkey script to translate the Dvorak layout back to QWERTY when the Ctrl, Alt, or Win keys are pressed in conjunction with other keys. It works beautifully everywhere I've tried, except Visual Studio '08. It seems keystrokes are being caught before autohotkey can translate them.

Why is this happening and how do I fix this?

Below is an excerpt (from the start) of my script:

; control + letter ^;::^z ^q::^x ^j::^c ^k::^v 

Update: The script works fine on Win7 with ahk, vs08, and coderush freshly installed. The machine I'm having trouble with is running vista. Any thoughts on how to further diagnose?

Update 2: The script works fine with Vista and 2010 beta 2. Seems to be something with just vs 08 + vista. Gonna try a fresh install of vs08 tonight.

like image 255
Dane O'Connor Avatar asked Dec 11 '09 19:12

Dane O'Connor


People also ask

How do I turn off AutoHotkey?

You can use a suspend AutoHotkey function, just press [ESC] and the script stop working, press again and it works.

How do I turn off AutoHotkey shortcuts?

If you ever want to stop AutoHotKey from blocking any keys, select the “Suspend Hotkeys” option. Your AutoHotKey's tray icon will change from an “H” to an “S” to indicate that hotkeys are being blocked. To re-enable all hotkeys, repeat this same action again.

What do people use AutoHotkey for?

AutoHotkey scripts can be used to launch programs, open documents, and emulate keystrokes or mouse clicks and movements. AutoHotkey scripts can also assign, retrieve, and manipulate variables, run loops and manipulate windows, files, and folders.


2 Answers

Aha! I've figured it out. If ahk and the target app are not running under the same privileges (or user) ahk won't intercept/simulate keyboard events properly. In my case, visual studio was run with administrator (elevated) privileges while the ahk script was run as the currently logged on user.

Either of the following solved the problem:

  • Running both vs and ahk as the current user
  • Compiling the script and running both vs and the compiled app as administrator
like image 114
Dane O'Connor Avatar answered Oct 08 '22 05:10

Dane O'Connor


Just want to add a couple of points to solution found by the OP himself.

1) The problem is not with AHK and VS running with different permissions - its just that hotkeys created by a script running in a non-admin mode wouldn't work on applications running in the admin mode, but there would be no problem if it's the other way round.

2) There is no need to compile the script necessarily, just set autohotkey.exe to run in the admin mode (that's what I do), or alternatively create a shortcut to the particular script and set it to always run in admin mode. (btw, just to point out, there is no performance gain by running a compiled version of an AHK script, because the code is still interpreted - its just that now the interpreter is embedded in the executable created)

like image 40
Himanshu P Avatar answered Oct 08 '22 06:10

Himanshu P