EzDevInfo.com

autohotkey interview questions

Top autohotkey frequently asked interview questions

"Select to Copy and Middle Click to Paste" in Windows

Is there any application to mimic the "Select to Copy and Middle Click to Paste" behaviour in Windows? I was hoping to find an AutoHotkey script for this, but I couldn't. Maybe someone here could quickly hack one for this :).


Source: (StackOverflow)

Where can I find a macro recorder for Autohotkey? [closed]

I used a macro recorder for AutoHotkey in the past, but now I can't seem to find it at all.


Source: (StackOverflow)

Advertisements

How can I open a command prompt in current folder with a keyboard shortcut?

How can I open a command prompt in current folder with a keyboard shortcut in Windows 7?
Is there any way to implement this?
I think Autohotkey could do this, but don't know how.


Source: (StackOverflow)

How do I escape the '{' and '}' characters in an AutoHotKey script?

I'm trying to write a simple auto-replace script but can't find how to insert the '{}' characters.
The usual escape characters (backtick ` or backslash ) don't seem to work for curly brackets.
e.g.

:co:drf::$(document).ready(function(){space}`{`n`});{Left}{Left}{Left}{left}

gives

$(document).ready(function() 
);

rather than

$(document).ready(function() {
});

Source: (StackOverflow)

How to make mouse jump from one screen's border to another screen in a Windows PC with multidisplays?

My laptop, running Windows 7 Pro, is connected to a docking station with 3 monitors.

The screens' disposition is something like that :

enter image description here

  • Monitor 1 is 1366x768 (laptop)
  • Monitor 2 is 1920x1280
  • Monitor 3 is 1080x1920
  • Monitor 4 is 1080x1920

The question is

How can I make my mouse go directly from monitor 1 to monitor 4 or 3, without going through monitor 2 ?

I have some solutions by using shortcuts or mouse buttons, but I would like a total transparent solution.

Some programs are near to what I am looking for, but doesn't handle this specific configuration :

Maybe an AHK script will help ? Any other hints ?

Thanks !

Regards,

Edit: replace schema with screen capture.


Source: (StackOverflow)

How do you map a solo press of a modifier key to its own function or mapping on Windows?

Today on hacker news there was a clever article on custom shortcut keys.

The author talks about a technique for remapping a modifier key such as CTRL to ESC if CTRL were pressed without a modifier. This is useful in vim because of how often you need to press ESC.

Another technique he describes is mapping the open parenthesis, ( to the left shift key, and ) to the right shift key.

If another key is pressed when shift is held down, the shift key behaves normally.

The author describes the software he uses on OSX, but is there a way to do this on Windows?

I've heard of AutoHotKey but it seems to only fire macros when simple keys are pressed, rather than the conditional state switch that this would require.


Source: (StackOverflow)

Disabling Function Keys in Windows 8 with Autohotkey

I would need to use Autohotkey to disable Function keys ( F1 -F12 ) on my Lenovo ideapad u310, running a Windows 8. I need this in order to use the F1-F12 in applications such as Ableton Live. Additionally, if it's possible to program the Windows 8's stock features behind an Fn key (see nb below) that would be even better.

The autohotkey program itself is working just fine, I've tried bunch of things successfully. But for some reason, I can't disable the Function keys or re-map them. Function Keys in Windows 8 are by default programmed to do things like opening up Charm, controlling volume etc.

In Windows 8, the F10 key, for example, opens the second screen option. This means I can't use it for other purposes, because every time I press it the second screen option opens up. The audio software I use would badly require freeing those F1-F12 keys from Windows 8 features, such as the second screen example. Simply: I'd like the Function Keys do nothing at all by default, thus being "available" for certain software to utilize.

I tried the basic "F1::Return" but nothing. Any ideas? Any help would mean a lot :)

So is it even possible to override these Windows 8 interface features with autohotkey?

nb: There's a feature in Mac OS that I'm actually trying to somewhat emulate here. On a mac computer, you can choose to have the function keys' features behind the Fn button, so you have to always press Fn+function. This way the user can execute OS features BUT still use the function keys without the Fn button in any software (like pressing F5 for refresh on an internet browser etc.).


Source: (StackOverflow)

Disable Ctrl+Z shortcut or clear undo history in Windows Explorer?

Is there any way to disable the CTRL+Z (Undo) shortcut in Windows Explorer? Alternatively, is there a way to have Windows Explorer "forget" its undo history?

The reason I ask is that you may have done some file operations in Explorer (copying, renaming, etc.), and perhaps you don't reboot for days or longer (choosing to hibernate instead). The problem is that if you accidentally hit CTRL+Z one or more times (often mistaking which application you have in the foreground; using a dual-monitor setup will increase that likelihood), you may be undoing something that was done ages ago without realizing what happened.

Even if you do realize what has happened, you may not remember what the last several operations were that you did potentially days ago. As far as I can tell, there is no "Redo" function in Windows Explorer to save you. I can imagine scenarios in which this mistake could cause lots of problems.

If the shortcut can be disabled, it would at least force you to use the Edit > Undo menu item before doing something stupid. Otherwise if the undo history could be periodically cleared, that would prevent some very old operations from being undone.

Addendum: For those interested in implementing this, I created an AHK file that runs silently (the #NoTrayIcon option) from my Windows Startup folder. Besides some other useful shortcuts I incorporated, this is what it looks like:

#NoTrayIcon
SetTitleMatchMode RegEx
return

; Disable Ctrl+Z shortcut in Windows Explorer
;
#IfWinActive ahk_class ExploreWClass|CabinetWClass
^z::return
#IfWinActive

If you prefer feedback instead of CTRL+Z simply doing nothing, play a default sound or use MsgBox to cause a dialog to appear.

#IfWinActive ahk_class ExploreWClass|CabinetWClass
^z::
    ;Uncomment the feedback option you prefer below
    ;SoundPlay *-1
    ;MsgBox Ctrl+Z has been disabled.
return
#IfWinActive

Source: (StackOverflow)

Using the IfWinActive keyword in AutoHotKey

This question about the use of AutoHotKey is specific to a Windows LaTeX editor called TeXnicCenter.

So, I was trying to write my first AutoHotKey (AHK) script, and wanted the shortcuts to be available only when the TeXniceCenter window was active. AHK provides the IfWinActive keyword to deal with these scenarios, however, I ran into some difficulties in using this keyword.

Here is a draft file I wrote:

SetTitleMatchMode, 2
SetTitleMatchMode, Slow

#IfWinActive, .* TeXnicCenter *.
!t::
Send \texttt{{}{}}
return

The #IfWinActive, .* TeXnicCenter *. line, so that the pattern "TeXnicCenter" is found somewhere in the window name does not work.

There were some other options that I discarded

  • I use TeXnicCenter mainly with projects, so that the window name shows up as "projectname - TeXnicCenter", so it is not feasible to use this as the argument to IfWinActive. Note that the window name is TeXnicCenter if working on standalone documents.

  • Another option provided by AHK is that you use something called the ahk_class of the process, which is typically intuitive (and can be had from the handy bundled AHK tool, called Window Spy) -- for example, in the case of Chrome, it is Chrome_WidgetWin_1.

However, for TeXnicCenter, it shows the bizarre signature -- for example, for one of my projects, it is Afx:000000013F370000:8:0000000000010005:0000000000000000:0000000012B80087, and not only that, it is not constant across TeXnicCenter windows, as it usually is for other processes.

I am at a loss -- does anyone have experience setting up AHK with TeXnicCenter, and using the IfWinActive keyword? I have a feeling that this might be better directed at the developers of TeXnicCenter, but here's hoping.


Source: (StackOverflow)

How can I make multi-line AutoHotKey scripts more readable?

I want to create an AutoHotKey script that generates this text:

==videoReview
aspnetmvc
IDCODE
TITLE
DESC
10:00
viewable online
[[

]]
3
english
extras::$url=nnn;$reason=

Using a similar tool called Texter, I define it like this:

==videoReview
aspnetmvc
IDCODE
TITLE
DESC
10:00
viewable online
[[
%|
]]
3
english
extras::$url=nnn;$reason=

Very simple.

In AutoHotKey, on the other hand, my script looks messy and is hard to edit, like this:

==videoReview{ENTER}aspnetmvc{ENTER}IDCODE{ENTER}TITLE{ENTER}DESC
{ENTER}10:00{ENTER}viewable{ENTER}online{ENTER}[[{ENTER}{ENTER}
{ENTER}]]{ENTER}3{ENTER}english{ENTER}extras::$url=nnn;
$reason={Up}{Up}{Up}{Up}{Up}

Is there a way to make AutoHotKey scripts more readable than this by allowing for multiline format?

(besides this being a bit unreadable, it says hotstring maximum abbreviation length is 40)


Source: (StackOverflow)

Cannot get Windows snipping tool to auto run with AutoHotKey

I am trying to get Windows 7 sniping tool to run when I hit my PRINTSCREEN keyboard button with AUTOHOTKEY.

I have been unsuccessful so far though. Here is what I have for the AutoHotKey script.

I have tried this

PRINTSCREEN::Run, c:\windows\system32\SnippingTool.exe

and this

PRINTSCREEN::Run, SnippingTool.exe

and this

PRINTSCREEN::Run, SnippingTool

And all those give me this error when I hit the PRINTSCREEN button... alt text

It basicly says it cannot find the file, however the file path seems to be correct, I can copy paste it into a window and it opens the snipping tool, any ideas why it will not work?


Here is the full code to my AHK file...

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win7
; Author:         Jason Davis <friendproject@>
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

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


/*
PRINTSCREEN = Will run Windows 7 snipping tool
*/
PRINTSCREEN::Run, c:\windows\system32\SnippingTool.exe
return

Source: (StackOverflow)

AutoHotKey not working with Outlook 2010

I created a AutoHotKey script and compiled it to an exe.

I then ran the exe and ran Outlook 2010.

When I try to use my hotkeys I defined I get an error in the status bar saying "This modification is not allowed because the selection is locked."

I have done some reasearch and that error seams to be tied together with a Trail ending. But I am at a work computer and I am not running a trial.

Is there a way to fix this?

here is my ahk file

SendMode Input ; Recommended for new scripts due to its superior speed and reliability.

SendMode Input ; superior speed and reliability.

SetTitleMatchMode 2 ;allow partial match to window titles

;********************
;Hotkeys for Outlook 2010
;********************
;As best I can tell, the window text ‘NUIDocumentWindow’ is not present
;on any other items except the main window. Also, I look for the phrase
; ‘ – Microsoft Outlook’ in the title, which will not appear in the title (unless
;a user types this string into the subject of a message or task).
#IfWinActive – Microsoft Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow

y::HandleOutlookKeys("!hy", "y") ;calls archive macro
f::HandleOutlookKeys("^f", "f") ;forwards message
r::HandleOutlookKeys("^r", "r") ;replies to message
a::HandleOutlookKeys("^+r", "a") ;reply all
v::HandleOutlookKeys("^+v", "v") ;Move message box
+u::HandleOutlookKeys("^u", "+u") ;marks messages as unread
+i::HandleOutlookKeys("^q", "+i") ;marks messages as read (^q is read/unread toggle)
j::HandleOutlookKeys("{Down}", "j") ;move down in list
+j::HandleOutlookKeys("{Down}{Enter}", "+j") ;move down and select next item
k::HandleOutlookKeys("{Up}", "k") ;move up
+k::HandleOutlookKeys("{Up}{Enter}", "+k") ;move up and select next item
o::HandleOutlookKeys("^o", "o") ;open message
s::HandleOutlookKeys("{Insert}", "s") ;toggle flag (star)
c::HandleOutlookKeys("^n", "c") ;new message
/::HandleOutlookKeys("^e", "/") ;focus search box
.::HandleOutlookKeys("+{F10}", ".") ;Display context menu

#IfWinActive
;Passes Outlook a special key combination for custom keystrokes or normal key value, depending on context
HandleOutlookKeys( specialKey, normalKey ) {
    ;Activates key only on main outlook window, not messages, tasks, contacts, etc.
    IfWinActive, – Microsoft Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow, ,
    {
        ;Find out which control in Outlook has focus
        ControlGetFocus, currentCtrl
        ;MsgBox, Control with focus = %currentCtrl%
        ;set list of controls that should respond to specialKey. Controls are the list of emails and the main (and minor) controls of the reading pane, including controls when viewing certain attachments.
        ;Currently I handle archiving when viewing attachments of Word, Excel, Powerpoint, Text, jpgs, pdfs
        ;The control ‘RichEdit20WPT1' (email subject line) is used extensively for inline editing. Thus it had to be removed. If an email’s subject has focus, it won’t archive…
        ctrlList = Acrobat Preview Window1, AfxWndW5, AfxWndW6, EXCEL71, MsoCommandBar1, OlkPicturePreviewer1, paneClassDC1, RichEdit20WPT2, RichEdit20WPT4, RichEdit20WPT5, RICHEDIT50W1, SUPERGRID1, SUPERGRID2, _WwG1
        if currentCtrl in %ctrlList%
        {
            Send %specialKey%
            ;Allow typing normalKey somewhere else in the main Outlook window. (Like the search field or the folder pane.)
        } else {
            Send %normalKey%
        }
        ;Allow typing normalKey in another window type within Outlook, like a mail message, task, appointment, etc.
        } else {
            Send %normalKey%
    }
}

Source: (StackOverflow)

How can I use the keyboard to simulate mousewheel scrolling with AutoHotkey?

I'm looking for a way to scroll with the keyboard using AutoHotkey. It would be also great if I could tweak scrolling speed somehow.


Source: (StackOverflow)

AutoHotKey equivalent on Mac

I am looking for a Mac application similar to AutoHotkey. What are the best Mac applications in this category?


Source: (StackOverflow)

How can I use Autohotkey to focus on an existing Google Chrome tab, not a "container" window?

How can I use Autohotkey to focus on an existing Google Chrome tab, not a "container" window?

Details

Google Chrome seems to represent each window with a container window handle, which contains one or more tabs. The tabs (at least the current one), has its own window handle. The tab window handles have window titles (which currently all end in " - Google Chrome"), whereas the container window handle itself does not. The following autohotkey code does not work as intended for Google Chrome:

^+i::
if WinExist("ahk_class Chrome_WidgetWin_0")
    WinActivate
else
    Run "C:\Users\vleeshue\AppData\Local\Google\Chrome\Application\chrome.exe"
return

This binding will focus on a Google Chrome window if it exists or will run Google Chrome. However, it will often target the container window (in Window Spy, the window title is blank). Activating the container window disallows the use of Google Chrome keyboard shortcuts. The inaccessible keyboard shortcuts include the all important ctrl+l to access the omnibar. Since I have not yet found a way to consistently activate the tab window instead of the container window, my workaround is to use the mouse, but I'd prefer to avoid that if possible.

Window Spy Screenshots

Container Window Handle

Tab Window Handle

Background

Current Google Chrome Version: 5.0.317.2 dev

A common autohotkey binding I use is a keyboard shortcut to focus a specific application if it's already running or to run the application if it isn't running.

For example, I use this for foobar2000

^+m::
If WinExist("foobar2000")
    WinActivate
else
    Run "C:\Program Files (x86)\foobar2000\foobar2000.exe"
return

Source: (StackOverflow)