1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AutoHotKeyでホームポジションの住民になる

Last updated at Posted at 2023-06-02

この記事を書き始めた 2023/06/02 現在、私は沖縄にいるわけなのですが、台風2号のおかげで講義もなくなり、幾度となく繰り返される停電と復旧の影響でPCもろくに触れない 停電に怯えつつ自宅で開発に励んでおります。
さて、それだけ時間があれば無論PCの前に座る時間=キーボードと戯れる時間が増えるわけで、ホームポジションに引きこもりたい欲が出てきます。しかし、矢印キー、BackSpaceキー、Deleteキー......こいつらのためにホームポジションを出なければならない!なんということか!!
調べたら、Windows PCのキーバインドをカスタマイズできる「AutoHotKey」なるものがあるとか。今更感しかありませんが、ひとまず触ってみることにしました。

AutoHotKeyとは?

公式: AutoHotKey
公式ページ「What is it ?」という項目を辿っていくと、wikiに飛びました。読み進めてみます。

AutoHotkey is a free and open-source custom scripting language for Microsoft Windows, initially aimed at providing easy keyboard shortcuts or hotkeys, fast macro-creation and software automation that allows users of most levels of computer skill to automate repetitive tasks in any Windows application. User interfaces can easily be extended or modified by AutoHotkey (for example, overriding the default Windows control key commands with their Emacs equivalents).

どうやらWindowsでスクリプト言語とやらを書くと、キーボードやマウスでの操作を自動化できたり、新しくショートカットキーを割り当てられると......
割と多くの人が使ってるようなので、入れてみることにしました。

手順

  1. 公式ページからAutoHotKeyをインストール
  2. 自分の好きなようにカスタマイズしたスクリプトを.ahk形式で保存
  3. ダブルクリックなどで、先ほど作成した.ahkスクリプトを実行
  4. 終了: タスクバーのアイコンを右クリック -> Exit

簡単!

ちなみに、.ahkスクリプトのショートカットをスタートアップに登録しておけば、PCの起動時に自動的にこの設定を有効化してくれます。
起動後に毎回ダブルクリックしにいくのもめんどくさいので、Win+R -> shell:startup でスタートアップフォルダに入れておきましょう!

サンプル

サンプルとして、私が自分のPCで設定したものを載せておきます。

main.ahk
; non-conversion + w, s, a, d: Arrow key operation
sc07B & W::
    Send, {Blind}{Up}
sc07B & S::
    Send, {Blind}{Down}
sc07B & A::
    Send, {Blind}{Left}
sc07B & D::
    Send, {Blind}{Right}

; non-conversion + q: Backspace
; non-conversion + e: Delete
sc07B & Q::
    Send, {Backspace}
sc07B & E::
    Send, {Delete}

; Disable insert key (What is this key used for? I am constantly struggling with this.)
INS::
    return

; Input timestamp
^+d::
    FormatTime, TimeString, , yyyyMMdd
    Send, %TimeString%
    return

項目ごとに簡単に解説します。
前提として、構文は以下のようになっています。

  • 入力キー::出力キー
  • 出力キー部分に return を指定: 入力キーの無効化
  • ; はコメントアウト

矢印キーの設定

.ahk
sc07B & W::
    Send, {Blind}{Up}
sc07B & S::
    Send, {Blind}{Down}
sc07B & A::
    Send, {Blind}{Left}
sc07B & D::
    Send, {Blind}{Right}

sc07Bは無変換キーです。Spaceキーの横あたりにあるやつ。
個人的にこのキーを使うこともないので、 無変換キー+{WASD} で 矢印(カーソル移動)としました。
同時押し系の入力キーの指定は 〇 & △ で書けるので、直感的で良いですね。
ちなみにWASDで矢印にした理由は、私がよくPCでゲームをしていて、この移動方法に慣れているからです。Vimに慣れているかたはWASD -> HJKL とかに変更してみても良いかもしれませんね。

BackSpace, Delete

.ahk
sc07B & Q::
    Send, {Backspace}
sc07B & E::
    Send, {Delete}

BackspaceキーとDeleteキーです。
これも無変換キーと同時押しで、qeに割り当てています。
全部左手だけでできるのはとても楽です。

Insertキーの無効化

.ahk
INS::
    return

Insertキーって必要ですか?(Insert使うよ~って人がいたらコメントで教えてください)

タイムスタンプ

.ahk
; Input timestamp
^+d::
    FormatTime, TimeString, , yyyyMMdd
    Send, %TimeString%
    return

手入力で yyyymmdd 打つのはもうやめましょう。
ということで、Ctrl+Shift+D でタイムスタンプを入力できるようにしました。
数字キーやテンキーに手を伸ばさなくて良いのはもちろん、カレンダーを確認しなくても日付を入力できるのは革命ですね。楽しくて何度も入力してしまいます。20230602202306022023060220230603......
開発しているとよくある「いつの間にか日付が変わってた」問題も、これで気付くことができますね!

まとめ

日付入力は本当に革命だと思います。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?