Welcome to new things

[Technical] [Electronic work] [Gadget] [Game] memo writing

How to disable or change browser shortcut keys

I usually use Visual Studio Code (VSCode) to write programs, but I have recently been experimenting with an editor/development environment that runs in the browser, because I want to complete my work using only the browser and not VSCode.

I used to use an editor called Emacs and was familiar with its shortcut keys, so I set the same shortcut keys for the editor that runs in the browser.

However, even if shortcut keys were set, the same keys as those browser shortcut keys could not be set because the browser's original shortcut keys, such as "Ctrl+p to print," have higher priority.

If that is the case, I thought that some software that hacks the keystrokes and changes them to other keystrokes before they are transmitted to the browser would work, and I found software called "AutoHotKey.

www.autohotkey.com

Tried it and it worked!

Browser shortcut keys can now be disabled or set to a different function!

AutoHotKey" is a powerful software that allows you to change any shortcut key to your favorite setting, not just for browsers, but it was quite difficult to learn how to use...

So, as a reminder, here is a brief summary of how to use "AutoHotKey," although it is within the scope of the functions we used this time.

What is AutoHotKey?

AutoHotKey is software that watches for keyboard and mouse input and detects when a particular input is made, causing another input or action.

You can create your own shortcut keys or overwrite existing ones.

Installation and Execution

Download and install from the official website.

The file extension "ahk" will then be registered as an "AutoHotkKey" file.

AutoHotkKey" does not work by itself, but by writing a program in an ahk file and executing that program with "AutoHotKey".

Once executed, an icon will appear in the tray.

How to write a program

  • Write the key to watch followed by two ":" colons
  • Write the action below it.
  • Write "return" at the end of a series of actions to terminate
  • Comments can use ";" and "/* \~ */".
<ウォッチするキー>::
<アクション>
.
.
return

; 1行コメント
/*
  複数行コメント
*/

Example

As for the aforementioned "Ctrl+p", I changed it to "on the cursor" and set "Ctrl+Shift+p" to "print" instead, and the program is as follows.

^p::
Send, {Up}
return

^+p::
Send, {Ctrl Down}p{Ctrl Up}
return

Ctrl+p" sends "on the cursor" and "Ctrl+Shift+p" sends "Ctrl+p".

Hotkey

The key to watch is called "Hotkey" and is specified by writing the following

  • Character keys are written as they are.
  • Special Key Modifiers

    • If Ctrl is pressed, write "^".
    • If Shift was pressed, write "+".
    • If Alt was pressed, "!" is written

Example

; a
a::
MsgBox, Press a
return

; Ctrl + a
^a::
MsgBox, Press Ctrl + a
return

; Ctrl + Alt + a
^!a::
MsgBox, Press Ctrl + Alt + a
return

Other hotkeys, such as mouse buttons, can also be designated as hotkeys.

Once you start working with Hotkey, I think you will want to do a lot of elaborate things.

AutoHotKey is designed to handle most requests, but I couldn't summarize all the ways to do it here, so you may want to refer to the help when you start to elaborate.

https://www.autohotkey.com/docs/Hotkeys.htm

keycheck

Hotkeys are often assigned special keys, such as "no-conversion," etc. To find out how to specify such keys, do the following.

  1. Launch AutoHotKey
  2. Enter the key you want to look up
  3. [View]-[Key history and script info]
  4. You will then see a history of the keys you have entered
  5. If it is listed in the "Key" field, it can be written as a hotkey.
  6. If the "Key" item is "not found", add "sc" to the beginning of the "SC" value and write it as a hotkey.

For example, when assigning a function to the "non-conversion key", the "Key" of the "non-conversion key" is "not found" and the "SC" is "07B", as shown below.

sc07b::
MsgBox, Press sc07b
return

How to write Send keystrokes

To issue another keystroke after a HotKey is pressed, use the "Send" command. The following is how to write the key to be issued.

  • If a key is written as is, Key Down and Key Up for that key are issued.
  • Special keys are enclosed in "{}".
  • Explicitly separate Key Down and Key Up when holding down a key

For example, to issue "a", "on the cursor", and "Ctrl+a" with Ctrl+p, the following is used.

^p::
Send, a{Up}{Ctrl Down}a{Ctrl Up}
return

Commands may be listed in more than one place.

^p::
Send, a
Send, {Up}
Send, {Ctrl Down}
Send, a
Send, {Ctrl Up}
return

Disable shortcut keys

After a HotKey is pressed, you can disable the shortcut key by ending with "return" without writing any action.

^p::
return

Set shortcut keys for specific applications

If Hotkey is written directly, it becomes a shortcut key that is valid throughout Windows.

If you use #IfWinActive, you can make a shortcut key effective only for the specified window, so you can change only the shortcut key for the browser, as we did this time.

The "#IfWinActive" applies until the next "#IfWinActive", and "#IfWinActive" without specifying a window is the same as the Windows-wide shortcut key.

To specify the application by its executable name, write "#IfWinActive ahk_exe \".

For example, to set "Ctrl+p" only for Chrome and "Ctrl+a" for the whole, you can do the following

#IfWinActive ahk_exe chrome.exe
^p::
MsgBox, Window Chrome
return

#IfWinActive
^a::
MsgBox, Window All
return

App Confirmation

To set a shortcut key that specifies an app, specify the app by the name of the app executable file.

For example, in the case of Chrome, the executable file would be "chrome.exe", but you can use AutoHotKey to find out which window has which executable file name.

  1. Right-click on AutoHotKey in tray
  2. [Window Spy]
  3. Click on the title of the window you wish to examine

Hotkey with more than 2 characters

Hotkey is activated for a single input.

Emacs has commands that are triggered for two inputs, such as "Ctrl+x Ctrl+s to save".

In such cases, "KeyWait, \" can be used to trigger an action with two or more keystrokes in a pseudo manner by activating it with the first key while waiting for the next key.

; Ctrl+x Ctrl+s
^x::
KeyWait, x
KeyWait, s D
Send, {Ctrl Down}s{Ctrl Up}

KeyWait, \" waits until the key is Up, and "KeyWait, \ D" waits until the key is Down.

So, the above process is such that when "Ctrl+x" is pressed, it waits until "x" is released, then waits for "s" to be pressed, then "Ctrl+s" is issued.

Execution at Windows startup

Since the "ahk" file is associated with "AutoHotKey", to enable AutoHotKey at Windows startup, place a shortcut to the ahk file in the Windows startup folder.

Impressions, etc.

Since AutoHotKey is a special function software, I was worried about the stability of its operation, but so far it has been stable and working as expected.

AutoHotKey seems to have been expanded with more and more features later on, and the specifications are quite chaotic.

Reference Articles

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com