PUSH KEY動作を二つから8個にしました
# encoding: UTF-8 # 以下はサンプルプログラム # Ruby動作2.6で確認 # ボタンが押された時にこれらの変数をselected_btnextに代入して # メインルーチンにジャンプする $btnext_1 = "" $btnext_2 = "" $btnext_3 = "" $btnext_4 = "" $btnext_5 = "" $btnext_6 = "" $btnext_7 = "" $btnext_8 = "" # ボタンを押して選択される選択肢のID $selected_btnext = "a" # これがtrueになると終了する $exit = false require 'io/console' # ここからメインルーチン def bt_selected_gomain tmp_ch = "?" while 1 if $exit == true then break end case $selected_btnext when "a" then $btnext_1 = "aa" $btnext_2 = "ab" $btnext_3 = "ac" $btnext_4 = "ad" $btnext_5 = "ae" $btnext_6 = "af" $btnext_7 = "ag" $btnext_8 = "ah" print("zキーかxキーかcキーかvキーか\n") print("aキーかsキーかdキーかfキーを押してください\n") print("終了:qキー") while 1 tmp_ch = get_getc() if tmp_ch == "z" $selected_btnext = $btnext_1 break elsif tmp_ch == "x" $selected_btnext = $btnext_2 break elsif tmp_ch == "c" $selected_btnext = $btnext_3 break elsif tmp_ch == "v" $selected_btnext = $btnext_4 break elsif tmp_ch == "a" $selected_btnext = $btnext_5 break elsif tmp_ch == "s" $selected_btnext = $btnext_6 break elsif tmp_ch == "d" $selected_btnext = $btnext_7 break elsif tmp_ch == "f" $selected_btnext = $btnext_8 break elsif tmp_ch=="q" $exit = true print("QUIT") tmp_ch = get_getc() break end end # end of while B when "aa" then $btnext_1 = "a" print("あなたはzキーを押しましたね\n") print("NEXT:spaceキー") space_push_next $btnext_1 when "ab" then $btnext_1 = "a" print("あなたはxキーを押しましたね\n") print("NEXT:spaceキー") space_push_next $btnext_1 when "ac" then $btnext_1 = "a" print("あなたはcキーを押しましたね\n") print("NEXT:spaceキー") space_push_next $btnext_1 when "ad" then $btnext_1 = "a" print("あなたはvキーを押しましたね\n") print("NEXT:spaceキー") space_push_next $btnext_1 when "ae" then $btnext_1 = "a" print("あなたはaキーを押しましたね\n") print("NEXT:spaceキー") space_push_next $btnext_1 when "af" then $btnext_1 = "a" print("あなたはsキーを押しましたね\n") print("NEXT:spaceキー") space_push_next $btnext_1 when "ag" then $btnext_1 = "a" print("あなたはdキーを押しましたね\n") print("NEXT:spaceキー") space_push_next $btnext_1 when "ah" then $btnext_1 = "a" print("あなたはfキーを押しましたね\n") print("NEXT:spaceキー") space_push_next $btnext_1 end # end of case end # end of while A end # end of method def get_getc $stdin.raw do |io| ch = io.getc print ch print "\n\n" return ch end end def z_push_next p_next while 1 tmp_ch = get_getc() if tmp_ch == "z" $selected_btnext = p_next break end end # end of while end def space_push_next p_next while 1 tmp_ch = get_getc() if tmp_ch == " " $selected_btnext = p_next break end end # end of while end bt_selected_gomain