0

Hitting escape while in a menu typically closes the menu window. Is there a similar hotkey to close a menu as if I'd clicked "OK"?

I made a macro to quickly turn on or off elements in a program, which involves toggling a radial in a menu tab, then clicking OK. It works, but the macro has to tab several times to get to the OK button.

3 Answers3

1

You may use the free AutoHotkey V1.

The following example script will click the OK button in the active window or dialog when F9 is clicked:

F9::
ControlClick, OK, A
Return

After installing AutoHotKey, put the above text in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at
C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

Useful AutoHotkey documentation:

harrymc
  • 498,455
0

This is just an explanation of the comment by David Postill, which is succinct and correct.

The standard Windows dialogs, used by different applications, allow a hotkey and a default key to be assigned to each button (and to other areas of the dialog), but it is up to the developer of each application to decide how to assign a hotkey, or whether to make it the default key, i.e., Enter.

For example, in the dialog below from the application FontViewOK, the default button is OK, so pressing Enter selects OK.

FontViewOK dialog

In the Windows UAC dialog, below, the default button is No. Note also that the N is underlined, indicating that pressing AltN is a shortcut.

Windows UAC dialog

Obviously, where an action might have negative consequences, the developer should avoid making that keypress the default, or one likely to be pressed by reflex.

0

No. Some boxes are simply hardcoded not to use accelerator keys, so tab is your only way to go(without use of 3rd party).

Example, manipulating with Run box, can do anything with it, but cant underline OK or Cancel;

$cpuUsage = Get-WmiObject Win32_Processor | Select-Object -ExpandProperty LoadPercentage
$memory = Get-WmiObject Win32_OperatingSystem
$totalMemory = [math]::Round($memory.TotalVisibleMemorySize / 1MB, 2)
$freeMemory = [math]::Round($memory.FreePhysicalMemory / 1MB, 2)
$usedMemory = $totalMemory - $freeMemory
$systemInfo = "Current CPU Usage: $cpuUsage%`n"
$systemInfo += "RAM usage: $usedMemory/$totalMemory MB`n"
$dialogTitle = "Example of Run box on $($env:COMPUTERNAME)."

Add-Type @" using System; using System.Runtime.InteropServices;

public class Win32 {
    [DllImport("shell32.dll", EntryPoint = "#61", CharSet = CharSet.Unicode)]
    public static extern int RunFileDlg(
        IntPtr hWnd,
        IntPtr icon,
        string path,
        string title,
        string prompt,
        uint flags);
}

"@

$RFF_NOBROWSE = 1 $RFF_NODEFAULT = 2 $RFF_CALCDIRECTORY = 4 $RFF_NOLABEL = 8 $RFF_NOSEPARATEMEM = 14 $RFF_OK = 0x00008000

[Win32]::RunFileDlg([IntPtr]::Zero, [IntPtr]::Zero, $null, $dialogTitle, $systemInfo, $RFF_OK)

Save as Somename.ps1 and run. Notice how it even underlines Open(even by default as much as i tested it) when Alt is pressed, but doesnt do anything.

Danijel
  • 461