%
% anyremote configuration file for mouse & keyboard emulation
% by Dmitry Ashkadov

% STATUS stable
% XTEST yes
% SOUND no
% ENV no
% ALL_IN_ONE 

GuiAppName=Mouse and Keyboard
GuiAppBinary=true
GuiAppIcon=mouse.png
GuiAppType=Example
GuiAppProtocols=Server
GuiAppDesc=Mouse and Keyboard emulation

[Protocol]=Server

% redefine joystick keys
UP=Emulate(mousermove,0,-10);
DOWN=Emulate(mousermove,0,10);
LEFT=Emulate(mousermove,-10,0);
RIGHT=Emulate(mousermove,10,0);
FIRE=Make(var,AutoRepeat,by_value,false);Emulate(mouse,1);Make(var,AutoRepeat,by_value,true);

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Make(var,kbd_alt,by_value,);\
	Make(var,kbd_ctrl,by_value,);\
	Make(var,kbd_shift,by_value,);\
	Make(var,kbd_super,by_value,);\
	Make(var,mouse_lb,by_value,);\
	Make(var,help_text,by_value,\nThere are two modes: keyboard mode and mouse mode. Press # twice to change mode. Press 0 to show/hide a menu.\n);\
	Make(var,help_text_menu,by_value,\nMenu:\n 0 - hide menu\n 1 - toggle Alt\n 2 - toggle Super\n 3 - volume up\n 4 - toggle Ctrl\n 6 - volume down\n 7 - toggle Shift\n 9 - mute\n * - toggle Left Mouse Button\n # - show Menu [#]\n \nMenu [#]:\n 0 - hide menu\n 1 - suspend\n 2 - shutdown\n 3 - brightness up\n 6 - brightness down\n # - toggle fullscreen);\
	Macro(MacroContinueHelp);

% Parser skips too long strings.
MacroContinueHelp=\
	Make(var,help_text_kbd,by_value,\nKeyboard mode:\n 1 - menu\n 2 - up arrow\n 3 - Page Up\n 4 - left arrow\n 5 - Enter\n 6 - right arrow\n 7 - Escape\n 8 - down arrow\n 9 - Page Down\n * 0 - Space\n * 1 - Ins\n * 2 - Alt+up\n * 3 - Home\n * 4 - Alt+left\n * 5 - Tab\n * 6 - Alt+right\n * 7 - Del\n * 8 - Alt+down\n * 9 - End\n * * - Help\n * # - BackSpace);\
	Make(var,help_text_sharp,by_value,\n[#]:\n # 0 - Pause\n # 1 - HomePage \n # 2 - Plus\n # 3 - PrintScreen\n # 4 - Back\n # 5 - Refresh\n # 6 - Forward\n # 7 - Alt+Enter\n # 8 - Minus\n # 9 - Alt+Tab\n # * - Alt+F4\n # # - Change mode);\
	Make(var,help_text_mouse,by_value,\nMouse mode:\n 1 - Right click\n 2 - Move Up\n 3 - Scroll Up\n 4 - Move Left\n 5 - Left Click\n 6 - Move Right\n 7 - Esc\n 8 - Move Down\n 9 - Scroll Down\n * 4 - Scroll Left\n * 5 - Middle button\n * 6 - Scroll Right);

(Connect)=\
	Set(layout,default,keypad_only,ticker);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);

% Remote keyboard emulates mouse ======================================================
[Mode]=Mouse
   
(EnterMode)=\
	Set(icons,$(Mode),1,info,2,up,3,top,4,left,5,ok,6,right,7,no,8,down,9,bottom,*,question,0,favorites,#,refresh);\
	ExecAndSet(title,echo "$(Mode) [$(kbd_alt) $(kbd_ctrl) $(kbd_shift) $(kbd_super) $(mouse_lb)]");\
	Make(var,AutoRepeat,by_value,true);\
	Macro(KBDMOU_CFG_MENU);

(ExitMode)=Make(var,AutoRepeat,by_value,false);

KBDMOU_CFG_MENU=Set(menu,replace,);Macro(ALLIN1MENU)

Cancel=Exit
Back=Set(text,close);Macro(KBDMOU_CFG_MENU);

2=Emulate(mousermove,0,-10);
4=Emulate(mousermove,-10,0);
6=Emulate(mousermove,10,0);
8=Emulate(mousermove,0,10);

1=Make(var,AutoRepeat,by_value,false);Emulate(mouse,3);Make(var,AutoRepeat,by_value,true);
5=Make(var,AutoRepeat,by_value,false);Emulate(mouse,1);Make(var,AutoRepeat,by_value,true);

3=Emulate(mouse,4);
9=Emulate(mouse,5);

7=Make(var,AutoRepeat,by_value,false);Emulate(key,Escape);Make(var,AutoRepeat,by_value,true);

0=Make(var,prev_mode,echo "$(Mode)");Make(mode,Menu); 

*=Make(var,prev_mode,echo "$(Mode)");Make(mode,Mouse [*]);

#=Make(var,prev_mode,echo "$(Mode)");Make(var,next_mode,by_value,Keyboard);Make(mode,[#]);

[ModeEnd]

% Remote keyboard emulates keyboard =================================================================
[Mode]=Keyboard

(EnterMode)=\
	Set(icons,$(Mode),1,info,2,up,3,top,4,left,5,ok,6,right,7,no,8,down,9,bottom,*,question,0,favorites,#,refresh);\
	ExecAndSet(title,echo "$(Mode) [$(kbd_alt) $(kbd_ctrl) $(kbd_shift) $(kbd_super) $(mouse_lb)]");\
	Make(var,AutoRepeat,by_value,true);\
	Macro(KBDMOU_CFG_MENU);

(ExitMode)=Make(var,AutoRepeat,by_value,false);

KBDMOU_CFG_MENU=Set(menu,replace,);Macro(ALLIN1MENU)

Cancel=Exit
Back=Set(text,close);Macro(KBDMOU_CFG_MENU);

1=Make(var,AutoRepeat,by_value,false);Emulate(key,Menu);Make(var,AutoRepeat,by_value,true);

2=Make(var,AutoRepeat,by_value,false);Emulate(key,Up);Make(var,AutoRepeat,by_value,true);
4=Make(var,AutoRepeat,by_value,false);Emulate(key,Left);Make(var,AutoRepeat,by_value,true);
6=Make(var,AutoRepeat,by_value,false);Emulate(key,Right);Make(var,AutoRepeat,by_value,true);
8=Make(var,AutoRepeat,by_value,false);Emulate(key,Down);Make(var,AutoRepeat,by_value,true);

5=Make(var,AutoRepeat,by_value,false);Emulate(key,Return);Make(var,AutoRepeat,by_value,true);

7=Make(var,AutoRepeat,by_value,false);Emulate(key,Escape);Make(var,AutoRepeat,by_value,true);

3=Make(var,AutoRepeat,by_value,false);Emulate(key,Page_Up);Make(var,AutoRepeat,by_value,true);
9=Make(var,AutoRepeat,by_value,false);Emulate(key,Page_Down);Make(var,AutoRepeat,by_value,true);

0=Make(var,prev_mode,echo "$(Mode)");Make(mode,Menu); 

*=Make(var,prev_mode,echo "$(Mode)");Make(mode,Keyboard [*]);

#=Make(var,prev_mode,echo "$(Mode)");Make(var,next_mode,by_value,Mouse);Make(mode,[#]);

[ModeEnd]


% Menu =======================================================================================
[Mode]=Menu

(EnterMode)=\
	Set(icons,$(Mode),1,default,2,default,3,vol_up,4,default,5,default,6,vol_down,7,default,8,default,9,mute,*,default,0,no,#,favorites);\
	ExecAndSet(title,echo "$(Mode) [$(kbd_alt) $(kbd_ctrl) $(kbd_shift) $(kbd_super) $(mouse_lb)]");\
	Make(var,AutoRepeat,by_value,true);\
	Macro(KBDMOU_CFG_MENU);

(ExitMode)=Make(var,AutoRepeat,by_value,false);

KBDMOU_CFG_MENU=Set(menu,replace,);Macro(ALLIN1MENU)

Cancel=Exit;
Back=Set(text,close);Macro(KBDMOU_CFG_MENU);


1=Make(var,AutoRepeat,by_value,false);\
	Make(var,result,echo "$(kbd_alt)");\
	Macro(MacroAltDown, if [ $(result) = "" ]; then true; else false; fi; echo $?);\
	Macro(MacroAltUp, if [ $(result) = "" ]; then false; else true; fi; echo $?);\
	Make(var,AutoRepeat,by_value,true);\
	Make(mode,Menu);
MacroAltDown=Emulate(keydown,Alt_L);Make(var,kbd_alt,by_value,Alt);
MacroAltUp=Emulate(keyup,Alt_L);Make(var,kbd_alt,by_value,);


2=Make(var,AutoRepeat,by_value,false);\
	Make(var,result,echo "$(kbd_super)");\
	Macro(MacroSuperDown, if [ $(result) = ""]; then true; else false; fi; echo $?);\
	Macro(MacroSuperUp, if [ $(result) = "" ]; then false; else true; fi; echo $?);\
	Make(var,AutoRepeat,by_value,true);\
	Make(mode,Menu);
MacroSuperDown=Emulate(keydown,Super_L);Make(var,kbd_super,by_value,Sup);
MacroSuperUp=Emulate(keyup,Super_L);Make(var,kbd_super,by_value,);


4=Make(var,AutoRepeat,by_value,false);\
	Make(var,result,echo "$(kbd_ctrl)");\
	Macro(MacroCtrlDown, if [ $(result) = "" ]; then true; else false; fi; echo $?);\
	Macro(MacroCtrlUp, if [ $(result) = "" ]; then false; else true; fi; echo $?);\
	Make(var,AutoRepeat,by_value,true);\
	Make(mode,Menu);
MacroCtrlDown=Emulate(keydown,Control_L);Make(var,kbd_ctrl,by_value,Ctl);
MacroCtrlUp=Emulate(keyup,Control_L);Make(var,kbd_ctrl,by_value,);


7=Make(var,AutoRepeat,by_value,false);\
	Make(var,result,echo "$(kbd_shift)");\
	Macro(MacroShiftDown, if [ $(result) = "" ]; then true; else false; fi; echo $?);\
	Macro(MacroShiftUp, if [ $(result) = "" ]; then false; else true; fi; echo $?);\
	Make(var,AutoRepeat,by_value,true);\
	Make(mode,Menu);
MacroShiftDown=Emulate(keydown,Shift_L);Make(var,kbd_shift,by_value,Sh);
MacroShiftUp=Emulate(keyup,Shift_L);Make(var,kbd_shift,by_value,);


*=Make(var,AutoRepeat,by_value,false);\
	Make(var,result,echo "$(mouse_lb)");\
	Macro(MacroMouseLBDown, if [ $(result) = "" ]; then true; else false; fi; echo $?);\
	Macro(MacroMouseLBUp, if [ $(result) = "" ]; then false; else true; fi; echo $?);\
	Make(var,AutoRepeat,by_value,true);\
	Make(mode,Menu);
MacroMouseLBDown=Emulate(mousedown,1);Make(var,mouse_lb,by_value,LB);
MacroMouseLBUp=Emulate(mouseup,1);Make(var,mouse_lb,by_value,);


0=Make(mode,$(prev_mode));                                      

3=Make(var,AutoRepeat,by_value,false);Emulate(key,AudioRaiseVolume);Make(var,AutoRepeat,by_value,true);
6=Make(var,AutoRepeat,by_value,false);Emulate(key,AudioLowerVolume);Make(var,AutoRepeat,by_value,true);
9=Make(var,AutoRepeat,by_value,false);Emulate(key,AudioMute);Make(var,AutoRepeat,by_value,true);

#=Make(mode,Menu [#]);

[ModeEnd]




% Menu + # ============================================================================
[Mode]=Menu [#]

(EnterMode)=\
	Set(icons,$(Mode),1,exit,2,default,3,plus,4,exit,5,default,6,minus,7,default,8,default,9,default,*,default,0,no,#,fullscreen);\
	ExecAndSet(title,echo "$(Mode) [$(kbd_alt) $(kbd_ctrl) $(kbd_shift) $(kbd_super) $(mouse_lb)]");\
	Make(var,AutoRepeat,by_value,true);\
	Macro(KBDMOU_CFG_MENU);

(ExitMode)=Make(var,AutoRepeat,by_value,false);

KBDMOU_CFG_MENU=Set(menu,replace,);Macro(ALLIN1MENU)

Cancel=Exit
Back=Set(text,close);Macro(KBDMOU_CFG_MENU);

0=Make(mode,$(prev_mode));

3=Make(var,AutoRepeat,by_value,false);Emulate(key,MonBrightnessUp);Make(var,AutoRepeat,by_value,true);
6=Make(var,AutoRepeat,by_value,false);Emulate(key,MonBrightnessDown);Make(var,AutoRepeat,by_value,true);

#=Make(var,AutoRepeat,by_value,false);Set(fullscreen,toggle);Make(var,AutoRepeat,by_value,true);Make(mode,Menu);

1=Make(var,AutoRepeat,by_value,false);Emulate(key,by_value,0x1008ffa7);Make(var,AutoRepeat,by_value,true);

% 4=Exec(poweroff); 
4=Make(var,AutoRepeat,by_value,false);Emulate(key,PowerOff);Make(var,AutoRepeat,by_value,true);

[ModeEnd]

% Keyboard mode + * ===================================================================
[Mode]=Keyboard [*]

(EnterMode)=\
	Set(icons,$(Mode),1,pause,2,up,3,top,4,left,5,last,6,right,7,first,8,down,9,bottom,*,question,0,minus,#,first);\
	ExecAndSet(title,echo "$(Mode) [$(kbd_alt) $(kbd_ctrl) $(kbd_shift) $(kbd_super) $(mouse_lb)]");\
	Make(var,AutoRepeat,by_value,true);\
	Macro(KBDMOU_CFG_MENU);

(ExitMode)=Make(var,AutoRepeat,by_value,false);

KBDMOU_CFG_MENU=Set(menu,replace,);Macro(ALLIN1MENU)

Cancel=Exit
Back=Set(text,close);Macro(KBDMOU_CFG_MENU);Make(mode,Keyboard);

*=Make(mode,Help);

2=Make(var,AutoRepeat,by_value,false);Emulate(keydown,Alt_L,key,Up,keyup,Alt_L);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);
4=Make(var,AutoRepeat,by_value,false);Emulate(keydown,Alt_L,key,Left,keyup,Alt_L);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);
6=Make(var,AutoRepeat,by_value,false);Emulate(keydown,Alt_L,key,Right,keyup,Alt_L);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);
8=Make(var,AutoRepeat,by_value,false);Emulate(keydown,Alt_L,key,Down,keyup,Alt_L);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);

3=Make(var,AutoRepeat,by_value,false);Emulate(key,Home);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);
9=Make(var,AutoRepeat,by_value,false);Emulate(key,End);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);

1=Make(var,AutoRepeat,by_value,false);Emulate(key,Insert);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);
7=Make(var,AutoRepeat,by_value,false);Emulate(key,Delete);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);

5=Make(var,AutoRepeat,by_value,false);Emulate(key,Tab);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);

0=Make(var,AutoRepeat,by_value,false);Emulate(key,Space);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);
#=Make(var,AutoRepeat,by_value,false);Emulate(key,BackSpace);Make(var,AutoRepeat,by_value,true);Make(mode,Keyboard);

[ModeEnd]

% Mouse mode + * ===================================================================
[Mode]=Mouse [*]

(EnterMode)=\
	Set(icons,$(Mode),1,default,2,up,3,default,4,left,5,ok,6,right,7,default,8,down,9,default,*,question,0,default,#,default);\
	ExecAndSet(title,echo "$(Mode) [$(kbd_alt) $(kbd_ctrl) $(kbd_shift) $(kbd_super) $(mouse_lb)]");\
	Make(var,AutoRepeat,by_value,true);\
	Macro(KBDMOU_CFG_MENU);

(ExitMode)=Make(var,AutoRepeat,by_value,false);

KBDMOU_CFG_MENU=Set(menu,replace,);Macro(ALLIN1MENU)

Cancel=Exit
Back=Set(text,close);Macro(KBDMOU_CFG_MENU);Make(mode,Mouse);

*=Make(mode,Help);
 
2=Make(var,AutoRepeat,by_value,false);Emulate(mouse,4);Make(var,AutoRepeat,by_value,true);Make(mode,Mouse);
8=Make(var,AutoRepeat,by_value,false);Emulate(mouse,5);Make(var,AutoRepeat,by_value,true);Make(mode,Mouse);
5=Make(var,AutoRepeat,by_value,false);Emulate(mouse,2);Make(var,AutoRepeat,by_value,true);Make(mode,Mouse);
4=Make(var,AutoRepeat,by_value,false);Emulate(mouse,6);Make(var,AutoRepeat,by_value,true);Make(mode,Mouse);
6=Make(var,AutoRepeat,by_value,false);Emulate(mouse,7);Make(var,AutoRepeat,by_value,true);Make(mode,Mouse);

1=Make(mode,Mouse);
3=Make(mode,Mouse);
7=Make(mode,Mouse);
9=Make(mode,Mouse);
0=Make(mode,Mouse);
#=Make(mode,Mouse);

[ModeEnd]


% Keyboard or mouse mode + # ===================================================================
[Mode]=[#]

(EnterMode)=\
	Set(icons,$(prev_mode) $(Mode),1,file,2,plus,3,fit,4,left,5,refresh,6,right,7,info,8,minus,9,launch,*,no,0,pause,#,refresh);\
	ExecAndSet(title,echo "$(prev_mode) $(Mode) [$(kbd_alt) $(kbd_ctrl) $(kbd_shift) $(kbd_super) $(mouse_lb)]");\
	Make(var,AutoRepeat,by_value,true);\
	Macro(KBDMOU_CFG_MENU);

(ExitMode)=Make(var,AutoRepeat,by_value,false);

KBDMOU_CFG_MENU=Set(menu,replace,);Macro(ALLIN1MENU)

Cancel=Exit
Back=Set(text,close);Macro(KBDMOU_CFG_MENU);

1=Make(var,AutoRepeat,by_value,false);Emulate(key,by_value,0x1008FF18);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));

2=Make(var,AutoRepeat,by_value,false);Emulate(key,KP_Add);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));
8=Make(var,AutoRepeat,by_value,false);Emulate(key,KP_Subtract);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));

4=Make(var,AutoRepeat,by_value,false);Emulate(key,Back);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));
6=Make(var,AutoRepeat,by_value,false);Emulate(key,Forward);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));

3=Make(var,AutoRepeat,by_value,false);Emulate(key,Print);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));

5=Make(var,AutoRepeat,by_value,false);Emulate(key,by_value,0x1008FF29);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));

7=Make(var,AutoRepeat,by_value,false);Emulate(keydown,Alt_L,key,Return,keyup,Alt_L);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));
9=Make(var,AutoRepeat,by_value,false);Emulate(keydown,Alt_L,key,Tab,keyup,Alt_L);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));

*=Make(var,AutoRepeat,by_value,false);Emulate(keydown,Alt_L,key,F4,keyup,Alt_L);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));

0=Make(var,AutoRepeat,by_value,false);Emulate(key,Pause);Make(var,AutoRepeat,by_value,true);Make(mode,$(prev_mode));

#=Make(mode,$(next_mode));

[ModeEnd]

% Help ====================================================================
[Mode]=Help

(EnterMode)=\
	Set(icons,$(Mode),1,file,2,file,3,file,4,file,5,file,6,default,7,default,8,default,9,default,*,default,0,no,#,default);\
	ExecAndSet(title,echo "$(Mode)");\
	Make(var,AutoRepeat,by_value,true);\
	Macro(KBDMOU_CFG_MENU);

(ExitMode)=Make(var,AutoRepeat,by_value,false)

KBDMOU_CFG_MENU=Set(menu,replace,);Macro(ALLIN1MENU)

Cancel=Exit
Back=Set(text,close);Macro(KBDMOU_CFG_MENU);

1=Set(text,replace,Help,$(help_text));
2=Set(text,replace,Help,$(help_text_menu));
3=Set(text,replace,Help,$(help_text_kbd));
4=Set(text,replace,Help,$(help_text_mouse));
5=Set(text,replace,Help,$(help_text_sharp));
0=Make(mode,$(prev_mode));

[ModeEnd]


[End]
