(X-Plane)LuaMacroによる番目のキーボード
Stacks Image 7075
中央センターにあるのがX-Plane専用のラベル付きのキーボード

LuaMacrosホームページ:
https://translate.google.co.jp/translate?sl=en&tl=ja-jp&u=https%3A%2F%2Fgithub.com%2Fspiralofhope%2Fluamacros%2Fwiki

PCのどこかにこれが入っている必要がある。
Pasted Graphic

この中の「xpl_lmc_plugin」を下のようにプラグインフォルダへ入れると準備完了。

X-Planeプラグインフォルダにこれが入っている必要がある。
貼り付けた画像_2020_12_07_17_36

LuaMacros.exeを起動
左のボタンでファルを指定し、三角の実行ボタンをクリック。
キーボードのどれかのキーを押してキーボードを認識させれば使用できるようになる。
Pasted Graphic


-- assign logical name to macro keyboard
lmc_assign_keyboard('MACROS');

-- define callback for whole device
lmc_set_handler('MACROS',function(button, direction)
  if (direction == 1) then return end  -- ignore down
  if     (button == string.byte('C')) then lmc_spawn("calc")
  elseif (button == string.byte('N')) then lmc_spawn("notepad", "C:\\test.txt")
  elseif (button == string.byte('H')) then lmc_send_keys('Hello world')
  else print('Not yet assigned: ' .. button) 
  end
end)

上のスクリプトでは毎回、LuaMacroの画面をクリックしてキーボードを認識させる必要があります。
同じキーボードを使うなら起動のとき自動で認識させると面倒がなくなります。
そのためには「MACROS」という名前のキーボードのIDコードを取得する必要があります

次に、コードの最初の0000AAA値をそれに置き換えます。 これにより、毎回手動でキーボードを識別する必要がなくなります。




色んな設定が完了して、そのluaファイルを自動起動するようにするにはLuaMacrosをパラメーターで開始します。
Windowsが起動したら自動的にLuaMacrosを有効にするには、以下のバッチファイルが必要、そしてこのスクリプトの最後に作成したluaファイルへのパスを以下のように入れます。
ここでは「B737X_800_Zibo_keyboard.lua」がそのファイルへのパスになります。

LuaMacrosStartUp.bat(バッチファイル)メモ帳で作成できる。
echo off
start c:\luamacros\LuaMacros.exe -r c:\luamacros\B737X_800_Zibo_keyboard.lua


Windowsの下のパスの位置に、上で作成したバッチファイルを入れる。
"C:\Users\kazuoPC\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\LuaMacrosStartUp.bat

※AppDataは隠しファイルになっているので、表示から『隠しファイル』にチェックをいれる必要がある。日本語のWindowsではStart Menuはスタートメニュー、以下カタカナになっているところがある。

これで自動的に「
B737X_800_Zibo_keyboard.lua」ファイルをLuaMacroで開くことができるようになる。
開いたら、
LuaMacroの画面をクリックしてキーボードを認識させる必要があります。

更に便利にするためには、
LuaMacroの画面をクリックしないでもキーボードを認識させることです。
Windowsが起動したら自動的に最初から2番目のキーボードを指定して認識できるようになるので何もしないで良いということになります。指定以外のキーボードを使用する予定が無いならこの設定がベストになると思います。



実際に作成したのLuaファイル。
B737X_800_Zibo_keyboard.lua
clear() --clear the console from last run
local keyboardIdentifier = '0000AAA'
lmc_print_devices()

if keyboardIdentifier == '0000AAA' then
	lmc_assign_keyboard('MACROS');
else lmc_device_set_name('MACROS', keyboardIdentifier);
end



-- assign logical name to macro keyboard
--lmc_assign_keyboard('MACROS');
lmc_print_devices()

-- define callback for whole device
lmc_set_handler('MACROS',function(button, direction)

	-------------------------------------------------------------------------------------------------------------------
	-- 特殊設定項目。押している間実行、離して終了。押し続ける必要があるコマンドの場合ここ(direction == 1)に入れる必要がある。
	if (direction == 1) then
		if     (button == string.byte('F')) then lmc_xpl_command_begin('sim/engines/engage_starters')
		elseif (button == string.byte('G')) then lmc_xpl_command_begin('sim/general/hat_switch_up')
		elseif (button == string.byte('B')) then lmc_xpl_command_begin('sim/flight_controls/brakes_regular')
		elseif (button == string.byte('N')) then lmc_xpl_command_begin('laminar/B738/brake_smoothly')
		elseif (button == 38) then lmc_xpl_command_begin('sim/general/up')--上
		elseif (button == 40) then lmc_xpl_command_begin('sim/general/down')--下
		elseif (button == 37) then lmc_xpl_command_begin('sim/general/left')--左
		elseif (button == 39) then lmc_xpl_command_begin('sim/general/right')--右
		elseif (button == 104) then lmc_xpl_command_begin('sim/general/hat_switch_up')--上回転 ハットスイッチ
		elseif (button == 98) then lmc_xpl_command_begin('sim/general/hat_switch_down')--下回転 ハットスイッチ
		elseif (button == 100) then lmc_xpl_command_begin('sim/general/hat_switch_left')--左回転 ハットスイッチ
		elseif (button == 102) then lmc_xpl_command_begin('sim/general/hat_switch_right')--右回転 ハットスイッチ
		elseif (button == 103) then lmc_xpl_command_begin('sim/general/hat_switch_up_left')--左斜め上 ハットスイッチ
		elseif (button == 97) then lmc_xpl_command_begin('sim/general/hat_switch_down_left')--左斜め下 ハットスイッチ
		elseif (button == 105) then lmc_xpl_command_begin('sim/general/hat_switch_up_right')--右斜め上 ハットスイッチ
		elseif (button == 99) then lmc_xpl_command_begin('sim/general/hat_switch_down_right')--右斜め下 ハットスイッチ
		elseif (button == 96) then lmc_xpl_command_begin('sim/general/backward')--後
		elseif (button == 110) then lmc_xpl_command_begin('sim/general/forward')--前
		elseif (button == 107) then lmc_xpl_command('sim/general/zoom_in')--ズームイン
		elseif (button == 13) then lmc_xpl_command_begin('sim/general/zoom_out')--ズームアウト
		end
		return
	end
-- 一度だけ押すという、一般的なコマンド東等の場合はここに入れる
	if     (button == string.byte('F')) then lmc_xpl_command_end('sim/engines/engage_starters') print('キー ' .. button)
	elseif (button == string.byte('G')) then lmc_xpl_command_end('sim/general/hat_switch_up') print('キー ' .. button)
	elseif (button == string.byte('B')) then lmc_xpl_command_end('sim/flight_controls/brakes_regular') print('キー ' .. button)
	elseif (button == string.byte('N')) then lmc_xpl_command_end('laminar/B738/brake_smoothly') print('キー ' .. button)
		--移動
	elseif (button == 38) then lmc_xpl_command_end('sim/general/up') print('キー ' .. button)--上
	elseif (button == 40) then lmc_xpl_command_end('sim/general/down') print('キー ' .. button)--下
	elseif (button == 37) then lmc_xpl_command_end('sim/general/left') print('キー ' .. button)--左
	elseif (button == 39) then lmc_xpl_command_end('sim/general/right') print('キー ' .. button)--右
	elseif (button == 104) then lmc_xpl_command_end('sim/general/hat_switch_up') print('キー ' .. button)--上回転 ハットスイッチ
	elseif (button == 98) then lmc_xpl_command_end('sim/general/hat_switch_down') print('キー ' .. button)--下回転 ハットスイッチ
	elseif (button == 100) then lmc_xpl_command_end('sim/general/hat_switch_left') print('キー ' .. button)--左回転 ハットスイッチ
	elseif (button == 102) then lmc_xpl_command_end('sim/general/hat_switch_right') print('キー ' .. button)--右回転 ハットスイッチ
	elseif (button == 103) then lmc_xpl_command_end('sim/general/hat_switch_up_left') print('キー ' .. button)--左斜め上 ハットスイッチ
	elseif (button == 97) then lmc_xpl_command_end('sim/general/hat_switch_down_left') print('キー ' .. button)--左斜め下 ハットスイッチ
	elseif (button == 105) then lmc_xpl_command_end('sim/general/hat_switch_up_right') print('キー ' .. button)--右斜め上 ハットスイッチ
	elseif (button == 99) then lmc_xpl_command_end('sim/general/hat_switch_down_right') print('キー ' .. button)--右斜め下 ハットスイッチ
	elseif (button == 96) then lmc_xpl_command_end('sim/general/backward') print('キー ' .. button)--後
	elseif (button == 110) then lmc_xpl_command_end('sim/general/forward') print('キー ' .. button)--前
	elseif (button == 107) then lmc_xpl_command_end('sim/general/zoom_in') print('キー ' .. button)--ズームイン
	elseif (button == 13) then lmc_xpl_command_end('sim/general/zoom_out') print('キー ' .. button)--ズームアウト
		--elseif (button == string.byte('T')) then  print(lmc_get_xpl_variable('laminar/B738/electric/panel_brightness', 0))--ブライトパネル
	elseif (button == string.byte('T')) then  lmc_set_xpl_variable('laminar/B738/electric/panel_brightness', 0.1, 0)--ブライトパネル
		--elseif (button == 84) then lmc_set_xpl_variable('laminar/B738/electric/panel_brightness', 0.5, 0) print('キー ' .. button)--ブライトパネル

		--elseif (button == string.byte('T')) then print(lmc_get_xpl_variable('sim/flightmodel/engine/ENGN_thro', 0)) -- throttle of first engine
		--elseif (button == string.byte('T')) then lmc_set_xpl_variable('sim/flightmodel/engine/ENGN_thro', 0.3, 0) -- set throttle of second engine

		-------------------------------------------------------------------------------------------------------------------
		--elseif (button == string.byte('U')) then lmc_inc_xpl_array_variable('sim/flightmodel/engine/ENGN_thro', 0, 0, 0)
	elseif (button == 101) then lmc_xpl_command('sim/view/forward_with_panel') print('キー ' .. button)--デフォルトビュー

		--ブレーキ
		--以下のウゴキガオァシイ
	elseif (button == string.byte('V')) then lmc_xpl_command('sim/flight_controls/brakes_toggle_max') print('キー ' .. button)--パーキングブレーキ
	elseif (button == 16) then lmc_xpl_command('sim/engines/thrust_reverse_toggle')--逆噴射
	elseif (button == string.byte('M')) then lmc_xpl_command('sim/flight_controls/speed_brakes_toggle') print('キー ' .. button)--エアーブレーキ(V)

	elseif (button == 189) then lmc_xpl_command('laminar/B738/knob/left_wiper_dn') print('キー ' .. button)--左ワイパーダウン
		lmc_xpl_command('laminar/B738/knob/right_wiper_dn')--右ワイパーダウン^^^--^^---
	elseif (button == 222) then lmc_xpl_command('laminar/B738/knob/left_wiper_up') print('キー ' .. button)--左ワイパーダウン
		lmc_xpl_command('laminar/B738/knob/right_wiper_up')--右ワイパーダウン
	elseif (button == 220) then lmc_xpl_command('laminar/B738/toggle_switch/flt_dk_door_open') print('キー ' .. button)--ドアオープン
	elseif (button == 93) then 	lmc_xpl_command('sim/operation/toggle_yoke') print('キー ' .. button)--操縦桿の表示・非表示

	elseif (button == 119) then lmc_xpl_command('sim/operation/pause_toggle') print('キー ' .. button)--ポーズ
	elseif (button == 123) then lmc_xpl_command('sim/operation/toggle_settings_window') print('キー ' .. button)--機体設定
	elseif (button == 121) then lmc_xpl_command('sim/operation/contact_atc') print('キー ' .. button)--ATC画面
	elseif (button == 122) then lmc_xpl_command('sim/map/show_low_enroute') print('キー ' .. button)--MAP表示
	elseif (button == 120) then lmc_xpl_command('sim/operation/toggle_flight_config') print('キー ' .. button)--設定画面
	elseif (button == 226) then 	lmc_xpl_command('sim/operation/toggle_yoke') print('キー ' .. button)--操縦桿の表示・非表示v
	elseif (button == 18) then 	lmc_xpl_command('sim/replay/replay_toggle') print('キー ' .. button)--再生モードの切り替え

		--プッシュバック
	elseif (button == string.byte('Q')) then lmc_xpl_command('BetterPushback/reload_tug') print('キー ' .. button)--BetterPushback
	elseif (button == string.byte('W')) then lmc_xpl_command('BetterPushback/connect_first') print('キー ' .. button)--BetterPushback
	elseif (button == string.byte('E')) then lmc_xpl_command('BetterPushback/cab_camera') print('キー ' .. button)--BetterPushbackキャブカメラ
	elseif (button == string.byte('R')) then lmc_xpl_command('BetterPushback/recreate_scenery_routes') print('キー ' .. button)--BetterPushback
	elseif (button == string.byte('A')) then lmc_xpl_command('BetterPushback/start_planner') print('キー ' .. button)--BetterPushbackプラン
	elseif (button == string.byte('S')) then lmc_xpl_command('BetterPushback/stop_planner') print('キー ' .. button)--BetterPushback
	elseif (button == string.byte('D')) then lmc_xpl_command('BetterPushback/reconnect') print('キー ' .. button)--BetterPushback最初に接続する
	elseif (button == string.byte('Z')) then lmc_xpl_command('BetterPushback/start') print('キー ' .. button)--BetterPushback開始
	elseif (button == string.byte('X')) then lmc_xpl_command('BetterPushback/stop') print('キー ' .. button)--BetterPushback
	elseif (button == string.byte('C')) then lmc_xpl_command('BetterPushback/disconnect') print('キー ' .. button)--BetterPushback切り離す

		--ライト
	elseif (button == 243) then lmc_xpl_command('sim/lights/landing_lights_on') print('キー ' .. button)--ランディングライトオールオン
	elseif (button == 244) then lmc_xpl_command('sim/lights/landing_lights_off') print('キー ' .. button)
	elseif (button == string.byte('1')) then lmc_xpl_command('laminar/B738/switch/rwy_light_left_on') print('キー ' .. button)
	elseif (button == string.byte('2')) then lmc_xpl_command('laminar/B738/switch/rwy_light_right_on') print('キー ' .. button)
	elseif (button == string.byte('3')) then lmc_xpl_command('laminar/B738/toggle_switch/taxi_light_brigh_toggle') print('キー ' .. button)
	elseif (button == string.byte('4')) then lmc_xpl_command('laminar/B738/switch/logo_light_on') print('キー ' .. button)
	elseif (button == string.byte('5')) then lmc_xpl_command('laminar/B738/toggle_switch/position_light_up') print('キー ' .. button)
	elseif (button == string.byte('6')) then lmc_xpl_command('laminar/B738/toggle_switch/position_light_down') print('キー ' .. button)
	elseif (button == string.byte('7')) then lmc_xpl_command('sim/lights/beacon_lights_toggle') print('キー ' .. button)--ANTI COLLISION
	elseif (button == string.byte('8')) then lmc_xpl_command('laminar/B738/switch/wing_light_on') print('キー ' .. button)
	elseif (button == string.byte('9')) then lmc_xpl_command('laminar/B738/switch/wheel_light_on') print('キー ' .. button)
		--イカこのボタンあ使わないほうがいい
	elseif (button == 9) then lmc_xpl_command('sim/lights/landing_lights_off') print('キー ' .. button)
		lmc_xpl_command('laminar/B738/switch/rwy_light_left_off')
		lmc_xpl_command('laminar/B738/switch/rwy_light_right_off')
		lmc_xpl_command('laminar/B738/switch/wing_light_off')
		lmc_xpl_command('laminar/B738/switch/wheel_light_off')
		lmc_xpl_command('sim/lights/taxi_lights_off')

		--X-Camera
	elseif (button == 192) then lmc_xpl_command('SRS/X-Camera/Toggle_X-Camera_on_or_off') print('キー ' .. button)--X-Camera
	elseif (button == 219) then lmc_xpl_command('SRS/X-Camera/Toggle_Control_Panel_on_or_off') print('キー ' .. button)--X-Camera
	elseif (button == 187) then lmc_xpl_command('SRS/X-Camera/Enable_X-Camera') print('キー ' .. button)--X-Camera
	elseif (button == 186) then lmc_xpl_command('SRS/X-Camera/Disable_X-Camera') print('キー ' .. button)--X-Camera
	elseif (button == 221) then lmc_xpl_command('SRS/X-Camera/Toggle_Mini_Control_Panel') print('キー ' .. button)--X-Camer

		--ビュー
	elseif (button == 44) then lmc_xpl_command('sim/view/linear_spot') print('キー ' .. button)--固定表示
	elseif (button == 145) then lmc_xpl_command('sim/view/still_spot') print('キー ' .. button)--一点表示
	elseif (button == 19) then lmc_xpl_command('sim/view/runway') print('キー ' .. button)--滑走路
	elseif (button == 45) then lmc_xpl_command('sim/view/circle') print('キー ' .. button)--機体周り
	elseif (button == 36) then lmc_xpl_command('sim/view/chase') print('キー ' .. button)--追跡
	elseif (button == 33) then lmc_xpl_command('sim/view/tower') print('キー ' .. button)--管制塔
	elseif (button == 46) then lmc_xpl_command('sim/view/ridealong') print('キー ' .. button)--機上
	elseif (button == 35) then lmc_xpl_command('sim/view/track_weapon') print('キー ' .. button)--兵器追跡
	elseif (button == 34) then lmc_xpl_command('sim/view/free_camera') print('キー ' .. button)--フリーカメラ

	elseif (button == 111) then lmc_xpl_command('sim/view/forward_with_hud') print('キー ' .. button)--前面HUD
	elseif (button == 106) then lmc_xpl_command('sim/view/forward_with_nothing') print('キー ' .. button)--前面ディスプレイ
	elseif (button == 109) then lmc_xpl_command('sim/view/3d_cockpit_cmnd_look') print('キー ' .. button)--前面3Dパネル
		--elseif (button == 109) then lmc_xpl_command('sim/view/forward_with_2d_panel')--前面2Dパネル

elseif (button == string.byte('K')) then lmc_inc_xpl_array_variable('sim/flightmodel/engine/ENGN_thro', 0, 0.3)


	elseif (button ==27) then lmc_spawn ("explorer" , "C:\\X-Plane 11\\X-Plane.exe") print('キー ' .. button)--X-Planeスタート
	elseif (button == 112) then lmc_xpl_command('sim/operation/quit') print('キー ' .. button)	--X-Plane終了

	else print('未使用キー ' .. button)
		-- タスクバーを整理するためにウィンドウをトレイに非表示にする



		lmc.minimizeToTray = true
		--lmc_minimize()

	end

	-------------------------------------------------------------------------------------------------------------------
end)