umeruma
5/20/2016 - 7:10 AM

config for keyhac

config for keyhac

import sys
import os
import datetime

import pyauto
from keyhac import *
## IME切り替え

def configure(keymap):
    def switch_ime(flag):
        # if not flag:
        if flag:
            ime_status = 1
        else:
            ime_status = 0
        # IMEのON/OFFをセット
        keymap.wnd.setImeStatus(ime_status)

    def ime_on():
        switch_ime(True)
    def ime_off():
        switch_ime(False)
    # For Edit box, assigning Delete to C-D, etc

    keymap_global= keymap.defineWindowKeymap()

    # Like Alfred
    if 1:
        keymap_global[ "O-W-RShift" ] = "W-S"

    # Mac-like 言語切り替え
    if 1:
        # U- D- どちらも上書きしないと、Win-X としてショートカットが
        # 設定されているキーの(Cとか Hとか)入力ができなくなる模様
        keymap_global[ "U-LWin" ] = ime_off
        keymap_global[ "D-LWin" ] = ime_off
        keymap_global[ "O-LWin "] = ime_off
        keymap_global[ "U-RWin" ] = ime_on
        keymap_global[ "D-RWin" ] = ime_on
        keymap_global[ "O-RWin "] = ime_on

    # Emucsもどき
    if 1:
        keymap_global[ "C-D" ] = "Delete"              # Delete
        keymap_global[ "C-H" ] = "Back"                # Backspace
        keymap_global[ "C-K" ] = "S-End","C-X"         # Removing following text

        keymap_global[ "C-X" ] = keymap.defineMultiStrokeKeymap("C-X")

        keymap_global[ "C-P" ] = "Up"                  # Move cursor up
        keymap_global[ "C-N" ] = "Down"                # Move cursor down
        keymap_global[ "C-F" ] = "Right"               # Move cursor right
        keymap_global[ "C-B" ] = "Left"                # Move cursor left
        keymap_global[ "C-A" ] = "Home"                # Move to beginning of line
        keymap_global[ "C-E" ] = "End"                 # Move to end of line
        keymap_global[ "A-F" ] = "C-Right"             # Word right
        keymap_global[ "A-B" ] = "C-Left"              # Word left
        #keymap_global[ "C-V" ] = "PageDown"            # Page down
        keymap_global[ "A-V" ] = "PageUp"              # page up
        keymap_global[ "A-Comma" ] = "C-Home"          # Beginning of the document
        keymap_global[ "A-Period" ] = "C-End"          # End of the document
        keymap_global[ "C-X" ][ "C-F" ] = "C-O"        # Open file
        keymap_global[ "C-X" ][ "C-S" ] = "C-S"        # Save
        keymap_global[ "C-X" ][ "C-W" ] = "A-F","A-A"  # Save as
        keymap_global[ "C-X" ][ "U" ] = "C-Z"          # Undo
        #keymap_global[ "C-S" ] = "C-F"                 # Search
        keymap_global[ "A-X" ] = "C-G"                 # Jump to specified line number
        keymap_global[ "C-X" ][ "H" ] = "C-A"          # Select all
        #keymap_global[ "C-W" ] = "C-X"                 # Cut
        keymap_global[ "A-W" ] = "C-C"                 # Copy
        keymap_global[ "C-Y" ] = "C-V"                 # Paste
        keymap_global[ "C-X" ][ "C-C" ] = "A-F4"       # Exit

    # numkey もどき
    if 1:
        keymap_global[ "A-J" ] = "1"
        keymap_global[ "A-K" ] = "2"
        keymap_global[ "A-L" ] = "3"
        keymap_global[ "A-U" ] = "4"
        keymap_global[ "A-I" ] = "5"
        keymap_global[ "A-O" ] = "6"
        keymap_global[ "A-7" ] = "7"
        keymap_global[ "A-8" ] = "8"
        keymap_global[ "A-9" ] = "9"
        keymap_global[ "A-M" ] = "0"
        keymap_global[ "A-Slash" ] = "Plus"
        keymap_global[ "A-Plus" ] = "S-Plus"
        keymap_global[ "A-P" ] = "S-(186)"
        keymap_global[ "A-0" ] = "(221)"

    # JIS to US
    if 1:
        km_for_hhk( keymap)

    # S and S =========================================================
    if 0:
        # shiftと同等の機能を持つUser0を作成し、space_keyに割り当てる ------
        keymap.defineModifier( "Space", "User0" )
        # keyCodeの範囲は1から255であると考えてfor文でまわす
        for keycode in range(1, 255):
                keymap_global["U0-" + str(keycode)] = "shift-" + str(keycode)
        # spacekey_keyにワンショットモディファイアを設定 ----------------------
        keymap_global["O-Space"] = "Space"

    # S and S
    if 1:
        keymap.replaceKey("Space", "RShift")
        keymap_global["O-RShift"] = "Space"

def km_for_hhk( keymap):
    kmg = keymap.defineWindowKeymap()
    # 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"
    # S-- => _
    kmg[ "S-Minus" ] = "S-(226)"
    # ^ => =
    kmg[ "(222)" ] = "S-Minus"
    # S-^ => +
    kmg[ "S-(222)" ] = "S-Plus"
    # [ => \
    # S-[ => |
    keymap.replaceKey( "(220)", "(221)" )
    # 半角/全角 => `
    kmg[ "(243)" ] = "S-(192)"
    kmg[ "(244)" ] = "S-(192)"
    # S-半角/全角 => ~
    kmg[ "S-(243)" ] = "S-(222)"
    kmg[ "S-(244)" ] = "S-(222)"
    # @ => [
    # S-@ => {
    keymap.replaceKey( "(192)", "(219)" )
    # [ => ]
    # S-[ => }
    keymap.replaceKey( "(219)", "(221)" )
    # S-; => :
    kmg[ "S-Plus"  ] = "(186)"
    # : => '
    kmg[ "(186)"  ] = "S-7"
    # S-: => "
    kmg[ "S-(186)"  ] = "S-2"

    kmg[ "CloseBracket"  ] = "(220)"
    kmg[ "S-CloseBracket"  ] = "S-(220)"