keyhac: 英語/日本語キーボードのDvorak配列化

きっと世の中で必要な人は極端にすくないとおもいますが。。。


keyhacをつかって、
英語or日本語配列のキーボードをUS-Dvorak配列で使えるようにするkeyhacの設定例です。

km_dvorak()の中のENG＝１を０にすれば日本語キーボードをUS-Dvorak化する設定になります。

keyhac-1.6βで確認。

```python:config.py

from keyhac import *

def configure(keymap):

    km_dvorak( keymap )
    
#    keymap.replaceKey("(240)", "Ctrl")  # CapsLock -> Ctrl
    keymap.replaceKey("Caps", "Ctrl")
    
    # --------------------------------------------------------------------
    # config.py編集用のテキストエディタの設定

    # プログラムのファイルパスを設定 (単純な使用方法)
    if 1:
        keymap.editor = "c:\program files\sakura\sakura.exe"

    # 呼び出し可能オブジェクトを設定 (高度な使用方法)
    if 0:
        def editor(path):
            shellExecute( None, None, "notepad.exe", '"%s"'% path, "" )
        keymap.editor = editor
        
    # --------------------------------------------------------------------
    # 表示のカスタマイズ

    # フォントの設定
    keymap.setFont( "ＭＳ ゴシック", 12 )

    # テーマの設定
    keymap.setTheme("black")

    # --------------------------------------------------------------------

    # キーの単純な置き換え
    #keymap.replaceKey( "LWin", 235 )
    #keymap.replaceKey( "RWin", 255 )
    #keymap.replaceKey( "RAlt", "LWin" )   # 右alt -> 左Win
    #keymap.replaceKey( "RAlt", 235 )
    keymap.replaceKey( 21, "LWin")

    # ユーザモディファイアキーの定義
    #keymap.defineModifier( 235, "User0" )
    keymap.defineModifier( 21, "Win" )

    # どのウインドウにフォーカスがあっても効くキーマップ
    if 0:
        keymap_global = keymap.defineWindowKeymap()

        # USER0-↑↓←→ : 10pixel単位のウインドウの移動
        keymap_global[ "U0-Left"  ] = keymap.command_MoveWindow( -10, 0 )
        keymap_global[ "U0-Right" ] = keymap.command_MoveWindow( +10, 0 )
        keymap_global[ "U0-Up"    ] = keymap.command_MoveWindow( 0, -10 )
        keymap_global[ "U0-Down"  ] = keymap.command_MoveWindow( 0, +10 )

        # USER0-Shift-↑↓←→ : 1pixel単位のウインドウの移動
        keymap_global[ "U0-S-Left"  ] = keymap.command_MoveWindow( -1, 0 )
        keymap_global[ "U0-S-Right" ] = keymap.command_MoveWindow( +1, 0 )
        keymap_global[ "U0-S-Up"    ] = keymap.command_MoveWindow( 0, -1 )
        keymap_global[ "U0-S-Down"  ] = keymap.command_MoveWindow( 0, +1 )

        # USER0-Ctrl-↑↓←→ : 画面の端まで移動
        keymap_global[ "U0-C-Left"  ] = keymap.command_MoveWindow_MonitorEdge(0)
        keymap_global[ "U0-C-Right" ] = keymap.command_MoveWindow_MonitorEdge(2)
        keymap_global[ "U0-C-Up"    ] = keymap.command_MoveWindow_MonitorEdge(1)
        keymap_global[ "U0-C-Down"  ] = keymap.command_MoveWindow_MonitorEdge(3)

        # クリップボード履歴
        keymap_global[ "C-S-Z"   ] = keymap.command_ClipboardList     # リスト表示
        keymap_global[ "C-S-X"   ] = keymap.command_ClipboardRotate   # 直近の履歴を末尾に回す
        keymap_global[ "C-S-A-X" ] = keymap.command_ClipboardRemove   # 直近の履歴を削除
        keymap.quote_mark = "> "                                      # 引用貼り付け時の記号

        # USER0-F2 : サブスレッド処理のテスト
        def command_JobTest():

            def jobTest(job_item):
                import os
                import sys
                shellExecute( None, None, "notepad.exe", "", "" )

            def jobTestFinished(job_item):
                print("Done.")
            
            job_item = JobItem( jobTest, jobTestFinished )
            job_queue.enqueue(job_item)
            
        keymap_global[ "U0-F2" ] = command_JobTest

        # USER0-F3 : アプリケーションの起動テスト
        keymap_global[ "U0-F3" ] = keymap.command_ShellExecute( None, None, "notepad.exe", "", "" )


    if 0:
        # USER0-Alt-↑↓←→/Space/PageUp/PageDown : キーボードで擬似マウス操作
        keymap_global[ "U0-A-Left"  ] = keymap.command_MouseMove(-10,0)
        keymap_global[ "U0-A-Right" ] = keymap.command_MouseMove(10,0)
        keymap_global[ "U0-A-Up"    ] = keymap.command_MouseMove(0,-10)
        keymap_global[ "U0-A-Down"  ] = keymap.command_MouseMove(0,10)
        keymap_global[ "D-U0-A-Space" ] = keymap.command_MouseButtonDown('left')
        keymap_global[ "U-U0-A-Space" ] = keymap.command_MouseButtonUp('left')
        keymap_global[ "U0-A-PageUp" ] = keymap.command_MouseWheel(1.0)
        keymap_global[ "U0-A-PageDown" ] = keymap.command_MouseWheel(-1.0)


    # Editボックスで、C-Dを削除に当てるなど
    if 1:
        keymap_edit = keymap.defineWindowKeymap( class_name="Edit" )

        keymap_edit[ "C-D" ] = "Delete"
        keymap_edit[ "C-H" ] = "Back"
        keymap_edit[ "C-U" ] = "S-Home", "Delete"
        keymap_edit[ "C-K" ] = "S-End", "Delete"

    
    # メモ帳を使って、特定アプリケーションのカスタマイズのテスト
    if 0:
        keymap_notepad = keymap.defineWindowKeymap( exe_name="notepad.exe", class_name="Edit" )
    
        def command_HelloWorld():
            print("Hello World!")

        keymap_notepad[ "C-A" ] = command_HelloWorld
        keymap_notepad[ "C-C" ] = "Return"
        keymap_notepad[ "C-D" ] = "C-F"
        keymap_notepad[ "C-E" ] = "A-V", "A-S"
        keymap_notepad[ "C-F" ] = keymap.command_InputText( "qwerty" )
        keymap_notepad[ "C-G" ] = keymap.command_InputText( "テストTESTテスト" )


    # クリップボード履歴リスト表示のカスタマイズ
    if 1:
        import datetime

        # 定型文
        fixed_items = [
            ( "name@server.net",     "name@server.net" ),
            ( "住所",                "〒東京都品川区123-456" ),
            ( "電話番号",            "03-4567-8901" ),
            ( "config.pyを編集",     keymap.command_EditConfig ),
            ( "config.pyをリロード", keymap.command_ReloadConfig ),
        ]
        
        # 日時をペーストする機能
        def dateAndTime(fmt):
            def _dateAndTime():
                return datetime.datetime.now().strftime(fmt)
            return _dateAndTime    

        # 日時
        date_and_time_items = [
            ( "YYYY/MM/DD HH:MM:SS",   dateAndTime("%Y/%m/%d %H:%M:%S") ),
            ( "YYYY/MM/DD",            dateAndTime("%Y/%m/%d") ),
            ( "HH:MM:SS",              dateAndTime("%H:%M:%S") ),
            ( "YYYYMMDD_HHMMSS",       dateAndTime("%Y%m%d_%H%M%S") ),
            ( "YYYYMMDD",              dateAndTime("%Y%m%d") ),
            ( "HHMMSS",                dateAndTime("%H%M%S") ),
        ]

        keymap.cblisters += [
            ( "定型文",         cblister_FixedPhrase(fixed_items) ),
            ( "日時",           cblister_FixedPhrase(date_and_time_items) ),
            ]


# dvorak配列化
def km_dvorak( km ):
    ENG = 1
    kmg = km.defineWindowKeymap()
    # Alphabet replaces
    km.replaceKey( "R", "P" )
    km.replaceKey( "T", "Y" )
    km.replaceKey( "Y", "F" )
    km.replaceKey( "U", "G" )
    km.replaceKey( "I", "C" )
    km.replaceKey( "O", "R" )
    km.replaceKey( "P", "L" )
#    km.replaceKey( "A", "A" )
    km.replaceKey( "S", "O" )
    km.replaceKey( "D", "E" )
    km.replaceKey( "F", "U" )
    km.replaceKey( "G", "I" )
    km.replaceKey( "H", "D" )
    km.replaceKey( "J", "H" )
    km.replaceKey( "K", "T" )
    km.replaceKey( "L", "N" )
    km.replaceKey( "X", "Q" )
    km.replaceKey( "C", "J" )
    km.replaceKey( "V", "K" )
    km.replaceKey( "B", "X" )
    km.replaceKey( "N", "B" )
#    km.replaceKey( "M", "M" )
    # non-alphabet replace
    km.replaceKey( "Minus", "(219)" ) # "[" == "(219)"
    km.replaceKey( "(222)", "(221)" )  # "]" == "(221)"
    km.replaceKey( "W", "Comma" )
    km.replaceKey( "E", "Period" )
    km.replaceKey( "Comma" , "W" )
    km.replaceKey( "Period", "V" )
    km.replaceKey( "(191)", "Z" )     # '/" == "(191)"
    #
    if (ENG) :
        km.replaceKey( "Q", "(222)" )     # "'" == "(222)"
        km.replaceKey( "(219)", "(191)" ) # [ -> /
        km.replaceKey( "(221)", "Plus" )  # ] -> +(=)
        km.replaceKey( "(222)", "Minus" ) # "'" == "-"
        km.replaceKey( "Z", "(186)" )
        km.replaceKey( "(186)", "S" )		# ";" == "(186)"
        km.replaceKey( "(187)", "(221)" )	# "=" == "(187)"
    else : # Japanese keyboard to Eng Dvorak
        # 半角/全角 => `
        kmg[ "(243)" ] = "S-(192)"
        kmg[ "(244)" ] = "S-(192)"
        # S-半角/全角 => ~
        kmg[ "S-(243)" ] = "S-(222)"
        kmg[ "S-(244)" ] = "S-(222)"
        # S-2 => @
        kmg[ "S-2" ] = "(192)"
        # S-6 => ^
        kmg[ "S-6" ] = "(222)"
        # S-7 => &
        kmg[ "S-7" ] = "S-6"
        # S-8 => *
        kmg[ "S-8" ] = "S-(186)"
        # S-9 => (
        kmg[ "S-9" ] = "S-8"
        # S-0 => )
        kmg[ "S-0" ] = "S-9"
        # Q => '
        km.replaceKey( "Q", "(231)" )  # (231) dummy
        kmg[ "(231)" ]   = "S-7"
        # S-Q => "
        kmg[ "S-(231)" ] = "S-2"
        # @ => /
        # S-@ => ?
        km.replaceKey( "(192)", "(191)" )
        # [ => 
        km.replaceKey( "(219)", "(230)" )  # (230) dummy
        kmg[ "(230)" ] = "S-(189)"
        # S-[ => +
        kmg[ "S-(230)" ] = "S-(187)"
        # ] => \
        # S-] => |
        km.replaceKey( "(221)", "(220)" )
        # ' => = -
        kmg[ "(186)" ] = "Minus"
        # S-' => _
        kmg[ "S-(186)" ] = "S-(226)"
        # Z => ;
        km.replaceKey( "(090)", "(187)" )
        # S-Z => :
        kmg[ "S-(187)"  ] = "(186)"
        #
        km.replaceKey( "(187)", "S" )     # ";" == "(187)"
    #
    
    #
    kmg[ "S-Space" ] = "(243)" # Shift-Spaceで変換
```