> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# "Toggle" Hotkey for the Immediate Window
- URL: https://nolongerset.com/toggle-hotkey-for-the-immediate-window/
- Published: 2020-11-18T23:38:26.000Z
- Updated: 2026-05-08T13:07:46.000Z
- Description: Am I the only one who finds it annoying that [Ctl] + [G] doesn't *toggle* between the immediate window and the code window? Let's fix that.
- Author: Mike Wolfe
- Tags: AutoHotKey, #Import 2026-05-20 02:59

I try to use the keyboard as much as possible when developing. Something that always bugged me about the Immediate Window in VBA is that there are two different hotkeys to move back and forth between code and the immediate window.

To move from code to the immediate window, you press \[Ctl\] + \[G\]. To move back to the code window you would press \[F7\]. This always felt awkward to me, so I created a simple hotkey in my standard [Autohotkey](https://www.autohotkey.com/) script so that I can use \[Ctl\] + \[G\] to move back and forth in both directions.

I use the `[#IfWinActive](https://www.autohotkey.com/docs/commands/%5FIfWinActive.htm)` directive in Autohotkey to limit this hotkey to running only inside the VBA IDE:

```autohotkey
; VBA IDE
#IfWinActive ahk_class wndclass_desked_gsk
^g::   ; Ctl + g: Toggle immediate window
    WinGet, WindowUniqueID, ID, A
    ControlGetFocus, ControlID, ahk_id %WindowUniqueID%
    ControlGet, ControlHwnd, Hwnd,, %ControlID%, ahk_id %WindowUniqueID%
    ControlTextSize = 18  ; expand capacity to hold 9 two-byte (i.e., Unicode) characters in buffer "I-m-m-e-d-i-a-t-e"
    VarSetCapacity(ControlText, ControlTextSize)
    SendMessage, 0xD, ControlTextSize, &ControlText,, ahk_id %ControlHWND%  ; 0xD is WM_GETTEXT.
    If (ControlText="Immediate")
        Send {F7}
    Else
        Send ^g
    Return

; Turn off context-sensitivity
#IfWinActive
```

*Image modified from [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Modern%5FAutoHotkey%5FLogo%5F%28full%29.svg) by [Mike Wolfe](https://nolongerset.com/author/mike/)*