訂製按鍵映射 link

配置項 config.keymap 中包含一個事件名稱與觸發事件的快捷鍵系統的映射關係。

Note

許多用戶已經學會了Ren’Py的默認按鍵綁定,並希望各遊戲保持一致。

在Ren’Py快捷鍵系統中,使用字串表示滑鼠按鍵、遊戲手把按鍵和鍵盤按鍵。

滑鼠按鍵的快捷鍵格式是‘mouseup_#’或‘mousedown_#’,其中的 # 符號代表按鍵的編號。Ren’Py假設滑鼠有5個按鍵,其中按鍵1、2、3分別表示左、中、右鍵,按鍵4和5分別表示滾輪的上滑和下滑。例如,“mousedown_1”代表滑鼠左鍵按下,“mouseup_1”表示滑鼠左鍵彈起,“mousedown_4”表示滾輪上滑。

總共有兩種鍵盤的快捷鍵。第一種是字串裡只有一個字元,有某個按鍵被按下時生成。通常用於綁定字母或數字按鍵。典型的快捷鍵包括“a”、“A”和“7”等。 注意這裡的字母對大小寫敏感,“a”與“A”是不同字母。

鍵盤快捷鍵也可以是符號或者功能按鍵。可以是pygame.constants中定義的任意 K_ 形式常量。這種快捷鍵字串類似於 “K_BACKSPACE”、 “K_RETURN”和 “K_TAB”;完整的快捷鍵定義詳見 這裡

鍵盤快捷鍵可以使用下列前綴,與後面的字元用下劃線分割:

alt
當alt鍵被同時按下時匹配。不同時按下alt鍵的快捷鍵與不帶前綴的匹配。
meta
當meta、command或windows鍵被同時按下時匹配。不同時按下那些鍵的快捷鍵與不帶前綴的匹配。
ctrl
當ctrl鍵被同時按下時匹配。不同時按下ctrl鍵的快捷鍵與不帶前綴的匹配。(ctrl鍵很少用,因為它通常會觸發跳過。)
shift
當shift鍵被同時按下時匹配。
noshift
當shift鍵沒有被按下時匹配。一個 K_ 形式快捷鍵忽略shift按鍵狀態。
repeat
由於按鍵始終處於按下狀態時,則匹配為repeat。不帶這個前綴的快捷鍵不會匹配到repeat。

例如,快捷鍵“shift_alt_K_F5”,當shift和alt鍵一直按下時,按下F5可以匹配到。

要修改快捷鍵和事件的綁定關係,就需要修改 config.keymap。下面的腳本將“t”鍵添加到按鍵列表中,作用是dismiss某say語句,並從列表中移除了空格鍵。

init:
    $ config.keymap['dismiss'].append('t')
    $ config.keymap['dismiss'].remove('K_SPACE')

預設的按鍵映射放在renpy/common/00keymap.rpy文件中,下面是7.4版本的配置:

config.keymap = dict(

    # 除非明確禁用,各處都能使用的綁定快捷鍵。
    rollback = [ 'K_PAGEUP', 'repeat_K_PAGEUP', 'K_AC_BACK', 'mousedown_4' ],
    screenshot = [ 's', 'alt_K_s', 'alt_shift_K_s', 'noshift_K_s' ],
    toggle_afm = [ ],
    toggle_fullscreen = [ 'f', 'alt_K_RETURN', 'alt_K_KP_ENTER', 'K_F11', 'noshift_K_f' ],
    game_menu = [ 'K_ESCAPE', 'K_MENU', 'K_PAUSE', 'mouseup_3' ],
    hide_windows = [ 'mouseup_2', 'h', 'noshift_K_h' ],
    launch_editor = [ 'E', 'shift_K_e' ],
    dump_styles = [ ],
    reload_game = [ 'R', 'alt_shift_K_r', 'shift_K_r' ],
    inspector = [ 'I', 'shift_K_i' ],
    full_inspector = [ 'alt_shift_K_i' ],
    developer = [ 'shift_K_d', 'alt_shift_K_d' ],
    quit = [ ],
    iconify = [ ],
    help = [ 'K_F1', 'meta_shift_/' ],
    choose_renderer = [ 'G', 'alt_shift_K_g', 'shift_K_g' ],
    progress_screen = [ 'alt_shift_K_p', 'meta_shift_K_p', 'K_F2' ],
    accessibility = [ "K_a" ],

    # 數據讀取。
    self_voicing = [ 'v', 'V', 'alt_K_v', 'K_v' ],
    clipboard_voicing = [ 'C', 'alt_shift_K_c', 'shift_K_c' ],
    debug_voicing = [ 'alt_shift_K_v', 'meta_shift_K_v' ],

    # say相關。
    rollforward = [ 'mousedown_5', 'K_PAGEDOWN', 'repeat_K_PAGEDOWN' ],
    dismiss = [ 'mouseup_1', 'K_RETURN', 'K_SPACE', 'K_KP_ENTER', 'K_SELECT' ],
    dismiss_unfocused = [ ],

    # 暫停。
    dismiss_hard_pause = [ ],

    # 焦點相關。
    focus_left = [ 'K_LEFT', 'repeat_K_LEFT' ],
    focus_right = [ 'K_RIGHT', 'repeat_K_RIGHT' ],
    focus_up = [ 'K_UP', 'repeat_K_UP' ],
    focus_down = [ 'K_DOWN', 'repeat_K_DOWN' ],

    # 按鈕。
    button_ignore = [ 'mousedown_1' ],
    button_select = [ 'mouseup_1', 'K_RETURN', 'K_KP_ENTER', 'K_SELECT' ],
    button_alternate = [ 'mouseup_3' ],
    button_alternate_ignore = [ 'mousedown_3' ],

    # 輸入。
    input_backspace = [ 'K_BACKSPACE', 'repeat_K_BACKSPACE' ],
    input_enter = [ 'K_RETURN', 'K_KP_ENTER' ],
    input_left = [ 'K_LEFT', 'repeat_K_LEFT' ],
    input_right = [ 'K_RIGHT', 'repeat_K_RIGHT' ],
    input_up = [ 'K_UP', 'repeat_K_UP' ],
    input_down = [ 'K_DOWN', 'repeat_K_DOWN' ],
    input_delete = [ 'K_DELETE', 'repeat_K_DELETE' ],
    input_home = [ 'K_HOME' ],
    input_end = [ 'K_END' ],
    input_copy = [ 'ctrl_noshift_K_INSERT', 'ctrl_noshift_K_c' ],
    input_paste = [ 'shift_K_INSERT', 'ctrl_noshift_K_v' ],

    # 視口。
    viewport_leftarrow = [ 'K_LEFT', 'repeat_K_LEFT' ],
    viewport_rightarrow = [ 'K_RIGHT', 'repeat_K_RIGHT' ],
    viewport_uparrow = [ 'K_UP', 'repeat_K_UP' ],
    viewport_downarrow = [ 'K_DOWN', 'repeat_K_DOWN' ],
    viewport_wheelup = [ 'mousedown_4' ],
    viewport_wheeldown = [ 'mousedown_5' ],
    viewport_drag_start = [ 'mousedown_1' ],
    viewport_drag_end = [ 'mouseup_1' ],
    viewport_pageup = [ 'K_PAGEUP', 'repeat_K_PAGEUP' ],
    viewport_pagedown = [ 'K_PAGEDOWN', 'repeat_K_PAGEDOWN' ],

    # 這些按鍵控制跳過。
    skip = [ 'K_LCTRL', 'K_RCTRL' ],
    stop_skipping = [ ],
    toggle_skip = [ 'K_TAB' ],
    fast_skip = [ '>', 'shift_K_PERIOD' ],

    # Bar。
    bar_activate = [ 'mousedown_1', 'K_RETURN', 'K_KP_ENTER', 'K_SELECT' ],
    bar_deactivate = [ 'mouseup_1', 'K_RETURN', 'K_KP_ENTER', 'K_SELECT' ],
    bar_left = [ 'K_LEFT', 'repeat_K_LEFT' ],
    bar_right = [ 'K_RIGHT', 'repeat_K_RIGHT' ],
    bar_up = [ 'K_UP', 'repeat_K_UP' ],
    bar_down = [ 'K_DOWN', 'repeat_K_DOWN' ],

    # 刪除存檔。
    save_delete = [ 'K_DELETE' ],

    # 可拖拽組件。
    drag_activate = [ 'mousedown_1' ],
    drag_deactivate = [ 'mouseup_1' ],

    # 除錯控制台。
    console = [ 'shift_K_o', 'alt_shift_K_o' ],
    console_older = [ 'K_UP', 'repeat_K_UP' ],
    console_newer = [ 'K_DOWN', 'repeat_K_DOWN'],

    # 編導器
    director = [ 'noshift_K_d' ],

    # 忽略(保持後向相容)。
    toggle_music = [ 'm' ],
    viewport_up = [ 'mousedown_4' ],
    viewport_down = [ 'mousedown_5' ],

    # Profile命令。
    performance = [ 'K_F3' ],
    image_load_log = [ 'K_F4' ],
    profile_once = [ 'K_F8' ],
    memory_profile = [ 'K_F7' ],

    )

手把的綁定工作會有一點不同。手把綁定會將一個事件映射為一個或多個Ren’Py事件名。預設的手把綁定設置如下:

config.pad_bindings = {
    "pad_leftshoulder_press" : [ "rollback", ],
    "pad_lefttrigger_pos" : [ "rollback", ],
    "pad_back_press" : [ "rollback", ],

    "repeat_pad_leftshoulder_press" : [ "rollback", ],
    "repeat_pad_lefttrigger_pos" : [ "rollback", ],
    "repeat_pad_back_press" : [ "rollback", ],

    "pad_guide_press" : [ "game_menu", ],
    "pad_start_press" : [ "game_menu", ],

    "pad_y_press" : [ "hide_windows", ],

    "pad_rightshoulder_press" : [ "rollforward", ],
    "repeat_pad_rightshoulder_press" : [ "rollforward", ],

    "pad_righttrigger_pos" : [ "dismiss", "button_select", "bar_activate", "bar_deactivate" ],
    "pad_a_press" : [ "dismiss", "button_select", "bar_activate", "bar_deactivate"],
    "pad_b_press" : [ "button_alternate" ],

    "pad_dpleft_press" : [ "focus_left", "bar_left", "viewport_leftarrow" ],
    "pad_leftx_neg" : [ "focus_left", "bar_left", "viewport_leftarrow" ],
    "pad_rightx_neg" : [ "focus_left", "bar_left", "viewport_leftarrow" ],

    "pad_dpright_press" : [ "focus_right", "bar_right", "viewport_rightarrow" ],
    "pad_leftx_pos" : [ "focus_right", "bar_right", "viewport_rightarrow" ],
    "pad_rightx_pos" : [ "focus_right", "bar_right", "viewport_rightarrow" ],

    "pad_dpup_press" : [ "focus_up", "bar_up", "viewport_uparrow" ],
    "pad_lefty_neg" :  [ "focus_up", "bar_up", "viewport_uparrow" ],
    "pad_righty_neg" : [ "focus_up", "bar_up", "viewport_uparrow" ],

    "pad_dpdown_press" : [ "focus_down", "bar_down", "viewport_downarrow" ],
    "pad_lefty_pos" : [ "focus_down", "bar_down", "viewport_downarrow" ],
    "pad_righty_pos" : [ "focus_down", "bar_down", "viewport_downarrow" ],

    "repeat_pad_dpleft_press" : [ "focus_left", "bar_left", "viewport_leftarrow" ],
    "repeat_pad_leftx_neg" : [ "focus_left", "bar_left", "viewport_leftarrow" ],
    "repeat_pad_rightx_neg" : [ "focus_left", "bar_left", "viewport_leftarrow" ],

    "repeat_pad_dpright_press" : [ "focus_right", "bar_right", "viewport_rightarrow" ],
    "repeat_pad_leftx_pos" : [ "focus_right", "bar_right", "viewport_rightarrow" ],
    "repeat_pad_rightx_pos" : [ "focus_right", "bar_right", "viewport_rightarrow" ],

    "repeat_pad_dpup_press" : [ "focus_up", "bar_up", "viewport_uparrow" ],
    "repeat_pad_lefty_neg" : [ "focus_up", "bar_up", "viewport_uparrow" ],
    "repeat_pad_righty_neg" : [ "focus_up", "bar_up", "viewport_uparrow" ],

    "repeat_pad_dpdown_press" : [ "focus_down", "bar_down", "viewport_downarrow" ],
    "repeat_pad_lefty_pos" : [ "focus_down", "bar_down", "viewport_downarrow" ],
    "repeat_pad_righty_pos" : [ "focus_down", "bar_down", "viewport_downarrow" ],
}

手把按鍵的事件名格式是“pad_*button*_press”和“pad_*button*_release”。 模擬搖杆事件格式是“pad_*axis*_pos”、“pad_*axis*_neg”和“pad_*axis*_zero”。 持續按住某個按鍵時,遊戲手把會生成另一個事件,前綴為“repeat_”。

需要執行特定初始流程才能使用手把,預設是禁用狀態。包括任天堂Switch的Pro手把,在電腦上使用時會要求特殊的初始化流程。 控制器黑名單詳見 config.controller_blocklist