hotfix: убрал добавление лишней строки

hotfix: убрал добавление лишней строки

; #include KeyCodes.ahk
; ;#include ..\core\WorkWithModule.ahk

actionShowMethodsList() {
	Global

	putModuleInFile()
	SendInput, {home}
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionShowRegionsList() {
	Global

	putModuleInFile()
	SendInput, {home}
	ClipWait
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionShowExtFilesList() {
	Global

	; RunWait, wscript scripts\ExtFiles.js
	RunWait, system\OneScript\bin\oscript.exe scripts\ExtFiles.os,,Hide

	NewText := getTextFromFile()
	If (NewText <> "") {
		ClipWait
		Sleep 1
		set_locale_ru()
		SendInput, !%KeyA%
		SendInput, {DOWN}{DOWN}{Enter}
		Sleep 500
		SendInput, ^%KeyV%{Enter}
	}
}

actionShowScriptManager() {
	putSelectionInFile()
	RunWait, wscript scripts\scripts_manager.js
	if (ErrorLevel > 0) {
	; RunWait, system\OneScript\bin\oscript.exe scripts\.os,,Hide
		pasteTextFromFile()
	}
}

actionShowPrevWords() {
	putModuleInFileWithSavePosition()
	RunWait, wscript scripts\scripts.js tmp\module.txt words
	pasteTextFromFile()
}

actionGotoMethodBegin() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
}

actionGotoMethodEnd() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
		SendInput ^{SC01A}
	}
	SendInput, {home}
}

actionShowRegExSearch() {
	Global

	putModuleInFile()

	SendInput, {home}
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os RegExSearch,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		Sleep 1
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
}

actionShowRegExSearchLastResult() {
	Global

	SendInput, {home}
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
}

actionShowLastSelect() {
	Global

	SendInput, {home}
	; RunWait, wscript scripts.js null last
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionRunAuthorComments(data) {
	putSelectionInFile()
	RunWait, system\OneScript\bin\oscript.exe scripts\.os %data%,,Hide
	pasteTextFromFile()
}

actionRunLinksToItems() {
	putSelectionInFile()
	RunWait, wscript scripts\generator.js null simple-managment
	pasteTextFromFile()
}

actionShowCodeGenerator() {
	RunWait, wscript scripts\generator.js null generator
	pasteTextFromFile()
}

actionShowPreprocMethod() {
	set_locale_ru()
	RunWait, wscript scripts\scripts.js null preprocmenu
	set_locale_ru()
	FileRead, text, tmp\module.txt
	set_locale_ru()
	SendInput, %text%
}

actionShowSimpleMetaSearch() {
	Global

	SendInput, ^+%KeyC%
	Sleep 10
	SendInput ^%KeyF%
}

actionShowIncomingObjectTypes() {
	Global

	SendInput, %KeyContextMenu%
	SendInput, {UP}{UP}{UP}{ENTER}
	Sleep 100
	SendInput, {Enter}
	SendInput, ^!%KeyO%
	SendInput, ^%KeyA%
	putSelectionInFile(0)
	module = tmp\module.txt
	SendInput, ^{END}
	RunWait, wscript scripts\scripts.js %module% gototype
	if (ErrorLevel > 0) {
		UpCount := ErrorLevel
		Loop %UpCount%
		{
			SendInput, {UP}
		}
		SendInput, {ENTER}
	}
}

actionShowMetadataNavigator() {
	Global

	module = tmp\module.txt

	; clear old data
	FileDelete %module%
	FileAppend,, %module%
	RunWait, system\inputbox.exe %module%

	NewText := getTextFromFile()
	If (NewText <> "") {
		; go to service msgs
		SendInput, ^!%KeyO%
		SendInput, ^+%KeyC%
		; show search dlg
		SendInput, ^%KeyF%
		pasteTextFromFile()
		;SendInput, !{Insert}
		SendInput, {Enter}
		Sleep 2000
		SendInput, ^%KeyA%
		ClipWait
		SendInput, {Left}{Enter}
		putSelectionInFile(0)
		NewText := getTextFromFile()
		If (NewText <> "") {
			SendInput, ^{END}
			RunWait, wscript scripts\scripts.js %module% gotoobject
			NewText := getTextFromFile()
			If (NewText <> "") {
				SendInput, {Home}
				SendInput, ^%KeyF%
				SendInput +{ins}

				SendInput, !{Insert}
				ClipWait
				SendInput, {Enter}
				SendInput, {Enter}
			}
		}
	}
}

showMenu() {
	createMenuItems()
	Menu, Popup, Show
}

actionRun1Script() {
	module = tmp\module.os

	SendInput ^{SC01E}^{ins}{Left}
	ClipWait

	FileDelete %module%

	FileAppend, %Clipboard%, %module%, UTF-8
	RunWait, cmd "/K system\OneScript\bin\oscript.exe tmp/module.os"

}

actionGoToPrevContainedWord() {

	clipboard =

	SendInput ^+{left}^{ins}{right}

	module = tmp\module.txt
	ClipWait

	FileDelete %module%

	FileAppend, %Clipboard%, %module%, UTF-8
	RunWait, system\OneScript\bin\oscript.exe scripts\.os prev,,Hide
	if (ErrorLevel > 0) {
		UpCount := ErrorLevel
		Loop %UpCount%
		{
			SendInput, {left}
		}
	}
}

actionGoToNextContainedWord() {

	clipboard =

	SendInput ^+{right}^{ins}{left}

	module = tmp\module.txt
	ClipWait

	FileDelete %module%

	FileAppend, %Clipboard%, %module%, UTF-8
	RunWait, system\OneScript\bin\oscript.exe scripts\.os next,,Hide
	if (ErrorLevel > 0) {
		UpCount := ErrorLevel
		Loop %UpCount%
		{
			SendInput, {right}
		}
	}
}

actionShowMethodName() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide

}

actionGenerateServerMethodFromCurMethod() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide

}

actionRowMoveUp() {
	Global
	clipboard =

	SendInput {home}+{end}+{del}^{sc26}
	ClipWait
	SendInput {home}{up}{enter}{up}+{ins}
}

; #include KeyCodes.ahk
; ;#include ..\core\WorkWithModule.ahk

actionShowMethodsList() {
	Global

	putModuleInFile()
	SendInput, {home}
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionShowRegionsList() {
	Global

	putModuleInFile()
	SendInput, {home}
	ClipWait
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionShowExtFilesList() {
	Global

	; RunWait, wscript scripts\ExtFiles.js
	RunWait, system\OneScript\bin\oscript.exe scripts\ExtFiles.os,,Hide

	NewText := getTextFromFile()
	If (NewText <> "") {
		ClipWait
		Sleep 1
		set_locale_ru()
		SendInput, !%KeyA%
		SendInput, {DOWN}{DOWN}{Enter}
		Sleep 500
		SendInput, ^%KeyV%{Enter}
	}
}

actionShowScriptManager() {
	putSelectionInFile()
	RunWait, wscript scripts\scripts_manager.js
	if (ErrorLevel > 0) {
	; RunWait, system\OneScript\bin\oscript.exe scripts\.os,,Hide
		pasteTextFromFile()
	}
}

actionShowPrevWords() {
	putModuleInFileWithSavePosition()
	RunWait, wscript scripts\scripts.js tmp\module.txt words
	pasteTextFromFile()
}

actionGotoMethodBegin() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
}

actionGotoMethodEnd() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
		SendInput ^{SC01A}
	}
	SendInput, {home}
}

actionShowRegExSearch() {
	Global

	putModuleInFile()

	SendInput, {home}
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os RegExSearch,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		Sleep 1
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
}

actionShowRegExSearchLastResult() {
	Global

	SendInput, {home}
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
}

actionShowLastSelect() {
	Global

	SendInput, {home}
	; RunWait, wscript scripts.js null last
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%%nStr%{ENTER}
	}
	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionRunAuthorComments(data) {
	putSelectionInFile()
	RunWait, system\OneScript\bin\oscript.exe scripts\.os %data%,,Hide
	pasteTextFromFile()
}

actionRunLinksToItems() {
	putSelectionInFile()
	RunWait, wscript scripts\generator.js null simple-managment
	pasteTextFromFile()
}

actionShowCodeGenerator() {
	RunWait, wscript scripts\generator.js null generator
	pasteTextFromFile()
}

actionShowPreprocMethod() {
	set_locale_ru()
	RunWait, wscript scripts\scripts.js null preprocmenu
	set_locale_ru()
	FileRead, text, tmp\module.txt
	set_locale_ru()
	SendInput, %text%
}

actionShowSimpleMetaSearch() {
	Global

	SendInput, ^+%KeyC%
	Sleep 10
	SendInput ^%KeyF%
}

actionShowIncomingObjectTypes() {
	Global

	SendInput, %KeyContextMenu%
	SendInput, {UP}{UP}{UP}{ENTER}
	Sleep 100
	SendInput, {Enter}
	SendInput, ^!%KeyO%
	SendInput, ^%KeyA%
	putSelectionInFile(0)
	module = tmp\module.txt
	SendInput, ^{END}
	RunWait, wscript scripts\scripts.js %module% gototype
	if (ErrorLevel > 0) {
		UpCount := ErrorLevel
		Loop %UpCount%
		{
			SendInput, {UP}
		}
		SendInput, {ENTER}
	}
}

actionShowMetadataNavigator() {
	Global

	module = tmp\module.txt

	; clear old data
	FileDelete %module%
	FileAppend,, %module%
	RunWait, system\inputbox.exe %module%

	NewText := getTextFromFile()
	If (NewText <> "") {
		; go to service msgs
		SendInput, ^!%KeyO%
		SendInput, ^+%KeyC%
		; show search dlg
		SendInput, ^%KeyF%
		pasteTextFromFile()
		;SendInput, !{Insert}
		SendInput, {Enter}
		Sleep 2000
		SendInput, ^%KeyA%
		ClipWait
		SendInput, {Left}{Enter}
		putSelectionInFile(0)
		NewText := getTextFromFile()
		If (NewText <> "") {
			SendInput, ^{END}
			RunWait, wscript scripts\scripts.js %module% gotoobject
			NewText := getTextFromFile()
			If (NewText <> "") {
				SendInput, {Home}
				SendInput, ^%KeyF%
				SendInput +{ins}

				SendInput, !{Insert}
				ClipWait
				SendInput, {Enter}
				SendInput, {Enter}
			}
		}
	}
}

showMenu() {
	createMenuItems()
	Menu, Popup, Show
}

actionRun1Script() {
	module = tmp\module.os

	SendInput ^{SC01E}^{ins}{Left}
	ClipWait

	FileDelete %module%

	FileAppend, %Clipboard%, %module%, UTF-8
	RunWait, cmd "/K system\OneScript\bin\oscript.exe tmp/module.os"

}

actionGoToPrevContainedWord() {

	clipboard =

	SendInput ^+{left}^{ins}{right}

	module = tmp\module.txt
	ClipWait

	FileDelete %module%

	FileAppend, %Clipboard%, %module%, UTF-8
	RunWait, system\OneScript\bin\oscript.exe scripts\.os prev,,Hide
	if (ErrorLevel > 0) {
		UpCount := ErrorLevel
		Loop %UpCount%
		{
			SendInput, {left}
		}
	}
}

actionGoToNextContainedWord() {

	clipboard =

	SendInput ^+{right}^{ins}{left}

	module = tmp\module.txt
	ClipWait

	FileDelete %module%

	FileAppend, %Clipboard%, %module%, UTF-8
	RunWait, system\OneScript\bin\oscript.exe scripts\.os next,,Hide
	if (ErrorLevel > 0) {
		UpCount := ErrorLevel
		Loop %UpCount%
		{
			SendInput, {right}
		}
	}
}

actionShowMethodName() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide

}

actionGenerateServerMethodFromCurMethod() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide

}

actionRowMoveUp() {
	Global
	clipboard =

	SendInput {home}+{end}+{del}
	ClipWait
	SendInput {home}{up}{enter}{up}+{ins}
}


A bit easier to hit these if they're shifted to the right one

; adapted from https://autohotkey.com/board/topic/51959-using-capslock-as-another-modifier-key/

$*Capslock::
Gui, 99:+ToolWindow
Gui, 99:Show, NoActivate, Capslock Is Down
keywait, Capslock
Gui, 99:Destroy
return

#IfWinExist, Capslock Is Down
; vimish
h::Left
j::Down
k::Up
l::Right
; could try to be vimish on these, but can't really do $ with left pinky already on capslock
u::Home
m::End
i::PgUp
,::PgDn
BackSpace::Del
#IfWinExist

; adapted from https://autohotkey.com/board/topic/51959-using-capslock-as-another-modifier-key/

$*Capslock::
Gui, 99:+ToolWindow
Gui, 99:Show, NoActivate, Capslock Is Down
keywait, Capslock
Gui, 99:Destroy
return

#IfWinExist, Capslock Is Down
; vimish
h::Left
j::Down
k::Up
l::Right
; could try to be vimish on these, but can't really do $ with left pinky already on capslock
y::Home
n::End
u::PgUp
m::PgDn
BackSpace::Del
#IfWinExist


add: detection of second screen taskbar for mouse wheel-controlled volume


Fix not hiding after start

Fix not hiding after start

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines -1 ; Execute the script at maximum speed

; Check for AHK version
if (A_AhkVersion < "1.1.21") {
	MsgBox, 48, AutoHotkey %A_AhkVersion%, Please update AutoHotkey. Version 1.1.21+ is required.
	ExitApp, 1
}

#Include assets\OSD.ahk
OSD("Emoji Keyboard")

#SingleInstance force
SendMode Input

; Required for the search mode
#MaxThreadsPerHotkey 2

; Setup tray menu
Menu, Tray, Icon, assets/keyboard.ico, 1, 1
Menu, Tray, Tip, Emoji Keyboard
Menu, Tray, Add, &Show, Toggle
Menu, Tray, Add
Menu, Tray, Add, Emoji &Keyboard by Gilles Waeber, Credits
Menu, Tray, Add
Menu, Tray, Add, E&xit, Exit
Menu, Tray, Default, &Show
Menu, Tray, NoStandard

#Include assets\JSON_ToObj.ahk
#Include assets\Webapp.ahk

__Webapp_GuiSize:
	global __WebappH, __WebappW
	__WebappH := A_GuiHeight
	__WebappW := A_GuiWidth
	RepositionGui()
return

RepositionGui() {
	global vSearch
	if (vSearch) {
		GuiControlGet, vPos, __Webapp_:Pos, SearchBox
		GuiControl, __Webapp_:Show, SearchBox
		GuiControl, __Webapp_:Move, SearchBox, W%__WebappW%
		webH := __WebappH - vPosH
	}
	else {
		GuiControl, __Webapp_:Hide, SearchBox
		webH := __WebappH
	}
	GuiControl, __Webapp_:Move, __Webapp_wb, Y%vPosH% W%__WebappW% H%webH%
}

__Webapp_AppStart:
	;<< Header End >>
	;             not focusable
	Gui __Webapp_:+E0x08000000 +AlwaysOnTop -MaximizeBox -MinimizeBox ; +E0x40000 +ToolWindow ;  -Caption
	OnMessage(0x112, "WM_SYSCOMMAND")
	Gui __Webapp_:Hide
Return

WM_SYSCOMMAND(wParam)
{
	global vVisible
    if (wParam = 0xF060 and vVisible) ; SC_CLOSE hide instead of closing
    {
        Hide()
        return 0
    }
}

; Variable containing the current state
vVisible := false
; Variable containing the searching state
vSearch := false
; Search Handler Semaphore (avoid multiple instances running)
vSearchSem := 1
vSearchInput := ""
; Save clipboard contents
clipSaved =
bClipSaved := False

; Change App name at run-time
setAppName("Emoji Keyboard")

; Our custom protocol's url event handler
app_call(args) {
	;MsgBox %args%
	param := SubStr(args, 6)
	if SubStr(args, 1, 5) = "send/"
		Send(param)
}

; Function to run when page is loaded
app_page(NewURL) {
}

; Change Hotkey here
Capslock::
	global vVisible
	if(vVisible){
		vVisible := false
		Hide()
		Return
	}
	Show()
Return

; Functions to be called from the html/js source
Exit() {
	ExitApp
}
Credits() {
	Run, https://github.com/romligCH/emoji-keyboard
}
Reload() {
	Reload
}

Send(t) {
	SetTimer, RestoreClipboard, Off
	global clipSaved, bClipSaved, vSearch
	if (vSearch) {
		Gui __Webapp_:Hide
	}
	if(not bClipSaved) {
		clipSaved := ClipboardAll
		bClipSaved := True
	}
	Clipboard := t
	Sleep, 10
	Send, ^v
	SetTimer, RestoreClipboard, 200
	if (vSearch) {
		Gui __Webapp_:Show
	}
}
RestoreClipboard() {
	global clipSaved, bClipSaved
	SetTimer, RestoreClipboard, Off
	Clipboard := clipSaved
	clipSaved =
	bClipSaved := False
}

Show() {
	global vVisible, vSearch
	vVisible := true
	Gui __Webapp_:Show, NA
	if (vSearch) {
		GuiControl, __Webapp_:Focus, SearchBox
	}
}
Hide() {
	global vVisible, vSearch
	vVisible := false
	Gui __Webapp_:Hide
}
Toggle() {
	global vVisible
	if(vVisible){
		Hide()
	}
	else{
		Show()
	}
}

Ready() {
	global j
	getDOM().document.ahk.setKeymap(j.keymap)
	getDOM().document.ahk.setOS(A_OSVersion)
}

SetTitle(t) {
	Gui __Webapp_:Show, NA, %t%
}

SearchChange() {
	GuiControlGet, str, __Webapp_:, SearchBox
	getDOM().document.ahk.setSearchText(str)
}

ToggleSearch() {
	global vSearch
	if vSearch
		SetSearch(false)
	else
		SetSearch(true)
}
SetSearch(s) {
	global vSearch
	oldSearch := vSearch
	vSearch := s
	if (oldSearch and !s) {
		RepositionGui()
		Gui __Webapp_:Show
		Gui __Webapp_:+E0x08000000
		Send !{Esc}
		getDOM().document.ahk.setSearch(false)
	}
	If (!oldSearch and s) {
		RepositionGui()
		Gui __Webapp_:-E0x08000000
		Gui __Webapp_:Show
		getDOM().document.ahk.setSearch(true)
		GuiControl, __Webapp_:Focus, SearchBox
	}
}

#If vVisible
; Corresponding keys                    		;	US	CH
SC029::getDOM().document.ahk.input(41)   		;	`	§
SC002::getDOM().document.ahk.input(2)    		;	1	1
SC003::getDOM().document.ahk.input(3)   		;	2	2
SC004::getDOM().document.ahk.input(4)   		;	3	3
SC005::getDOM().document.ahk.input(5)   		;	4	4
SC006::getDOM().document.ahk.input(6)   		;	5	5
SC007::getDOM().document.ahk.input(7)   		;	6	6
SC008::getDOM().document.ahk.input(8)   		;	7	7
SC009::getDOM().document.ahk.input(9)   		;	8	8
SC00A::getDOM().document.ahk.input(10)   		;	9	9
SC00B::getDOM().document.ahk.input(11)   		;	0	0
SC00C::getDOM().document.ahk.input(12)   		;	-	'
SC00D::getDOM().document.ahk.input(13)   		;	=	^
+SC029::getDOM().document.ahk.input(41, True)  	;	`	§
+SC002::getDOM().document.ahk.input(2, True)	;	1	1
+SC003::getDOM().document.ahk.input(3, True)	;	2	2
+SC004::getDOM().document.ahk.input(4, True)	;	3	3
+SC005::getDOM().document.ahk.input(5, True)	;	4	4
+SC006::getDOM().document.ahk.input(6, True)	;	5	5
+SC007::getDOM().document.ahk.input(7, True)	;	6	6
+SC008::getDOM().document.ahk.input(8, True)	;	7	7
+SC009::getDOM().document.ahk.input(9, True)	;	8	8
+SC00A::getDOM().document.ahk.input(10, True)	;	9	9
+SC00B::getDOM().document.ahk.input(11, True)	;	0	0
+SC00C::getDOM().document.ahk.input(12, True)	;	-	'
+SC00D::getDOM().document.ahk.input(13, True)	;	=	^
Tab::ToggleSearch()
+Tab::ToggleSearch()
#If vVisible and vSearch
^Backspace::GuiControl, __Webapp_:, SearchBox,  ; clear seach
#If vVisible and !vSearch
; Corresponding keys                    		;	US	CH
;SC001::getDOM().document.ahk.input(1)   		;	ESC	ESC
;SC03B::getDOM().document.ahk.input(59)   		;	F1	F1
;SC03C::getDOM().document.ahk.input(60)   		;	F2	F2
;SC03D::getDOM().document.ahk.input(61)   		;	F3	F3
;SC03E::getDOM().document.ahk.input(62)   		;	F4	F4
;SC03F::getDOM().document.ahk.input(63)   		;	F5	F5
;SC040::getDOM().document.ahk.input(64)   		;	F6	F6
;SC041::getDOM().document.ahk.input(65)   		;	F7	F7
;SC042::getDOM().document.ahk.input(66)   		;	F8	F8
;SC043::getDOM().document.ahk.input(67)   		;	F9	F9
;SC044::getDOM().document.ahk.input(68)   		;	F10	F10
;SC057::getDOM().document.ahk.input(87)   		;	F11	F11
;SC058::getDOM().document.ahk.input(88)   		;	F12	F12
SC010::getDOM().document.ahk.input(16)   		;	q	q
SC011::getDOM().document.ahk.input(17)   		;	w	w
SC012::getDOM().document.ahk.input(18)   		;	e	e
SC013::getDOM().document.ahk.input(19)   		;	r	r
SC014::getDOM().document.ahk.input(20)   		;	t	t
SC015::getDOM().document.ahk.input(21)   		;	y	z
SC016::getDOM().document.ahk.input(22)   		;	u	u
SC017::getDOM().document.ahk.input(23)   		;	i	i
SC018::getDOM().document.ahk.input(24)   		;	o	o
SC019::getDOM().document.ahk.input(25)   		;	p	p
SC01A::getDOM().document.ahk.input(26)   		;	[	èü
SC01B::getDOM().document.ahk.input(27)   		;	]	¨
SC01E::getDOM().document.ahk.input(30)   		;	a	a
SC01F::getDOM().document.ahk.input(31)   		;	s	s
SC020::getDOM().document.ahk.input(32)   		;	d	d
SC021::getDOM().document.ahk.input(33)   		;	f	f
SC022::getDOM().document.ahk.input(34)   		;	g	g
SC023::getDOM().document.ahk.input(35)   		;	h	h
SC024::getDOM().document.ahk.input(36)   		;	j	j
SC025::getDOM().document.ahk.input(37)   		;	k	k
SC026::getDOM().document.ahk.input(38)   		;	l	l
SC027::getDOM().document.ahk.input(39)   		;	;	éö
SC028::getDOM().document.ahk.input(40)   		;	'	àä
SC02B::getDOM().document.ahk.input(43)   		;	\	$
SC056::getDOM().document.ahk.input(86)   		;	\	<
SC02C::getDOM().document.ahk.input(44)   		;	z	y
SC02D::getDOM().document.ahk.input(45)   		;	x	x
SC02E::getDOM().document.ahk.input(46)   		;	c	c
SC02F::getDOM().document.ahk.input(47)   		;	v	v
SC030::getDOM().document.ahk.input(48)   		;	b	b
SC031::getDOM().document.ahk.input(49)   		;	n	n
SC032::getDOM().document.ahk.input(50)   		;	m	m
SC033::getDOM().document.ahk.input(51)   		;	,	,
SC034::getDOM().document.ahk.input(52)   		;	.	.
SC035::getDOM().document.ahk.input(53)   		;	/	-
+SC010::getDOM().document.ahk.input(16, True)	;	q	q
+SC011::getDOM().document.ahk.input(17, True)	;	w	w
+SC012::getDOM().document.ahk.input(18, True)	;	e	e
+SC013::getDOM().document.ahk.input(19, True)	;	r	r
+SC014::getDOM().document.ahk.input(20, True)	;	t	t
+SC015::getDOM().document.ahk.input(21, True)	;	y	z
+SC016::getDOM().document.ahk.input(22, True)	;	u	u
+SC017::getDOM().document.ahk.input(23, True)	;	i	i
+SC018::getDOM().document.ahk.input(24, True)	;	o	o
+SC019::getDOM().document.ahk.input(25, True)	;	p	p
+SC01A::getDOM().document.ahk.input(26, True)	;	[	èü
+SC01B::getDOM().document.ahk.input(27, True)	;	]	¨
+SC01E::getDOM().document.ahk.input(30, True)	;	a	a
+SC01F::getDOM().document.ahk.input(31, True)	;	s	s
+SC020::getDOM().document.ahk.input(32, True)	;	d	d
+SC021::getDOM().document.ahk.input(33, True)	;	f	f
+SC022::getDOM().document.ahk.input(34, True)	;	g	g
+SC023::getDOM().document.ahk.input(35, True)	;	h	h
+SC024::getDOM().document.ahk.input(36, True)	;	j	j
+SC025::getDOM().document.ahk.input(37, True)	;	k	k
+SC026::getDOM().document.ahk.input(38, True)	;	l	l
+SC027::getDOM().document.ahk.input(39, True)	;	;	éö
+SC028::getDOM().document.ahk.input(40, True)	;	'	àä
+SC02B::getDOM().document.ahk.input(43, True)	;	\	$
+SC056::getDOM().document.ahk.input(86, True)	;	\	<
+SC02C::getDOM().document.ahk.input(44, True)	;	z	y
+SC02D::getDOM().document.ahk.input(45, True)	;	x	x
+SC02E::getDOM().document.ahk.input(46, True)	;	c	c
+SC02F::getDOM().document.ahk.input(47, True)	;	v	v
+SC030::getDOM().document.ahk.input(48, True)	;	b	b
+SC031::getDOM().document.ahk.input(49, True)	;	n	n
+SC032::getDOM().document.ahk.input(50, True)	;	m	m
+SC033::getDOM().document.ahk.input(51, True)	;	,	,
+SC034::getDOM().document.ahk.input(52, True)	;	.	.
+SC035::getDOM().document.ahk.input(53, True)	;	/	-
#If

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines -1 ; Execute the script at maximum speed

; Check for AHK version
if (A_AhkVersion < "1.1.21") {
	MsgBox, 48, AutoHotkey %A_AhkVersion%, Please update AutoHotkey. Version 1.1.21+ is required.
	ExitApp, 1
}

#Include assets\OSD.ahk
OSD("Emoji Keyboard")

#SingleInstance force
SendMode Input

; Required for the search mode
#MaxThreadsPerHotkey 2

; Setup tray menu
Menu, Tray, Icon, assets/keyboard.ico, 1, 1
Menu, Tray, Tip, Emoji Keyboard
Menu, Tray, Add, &Show, Toggle
Menu, Tray, Add
Menu, Tray, Add, Emoji &Keyboard by Gilles Waeber, Credits
Menu, Tray, Add
Menu, Tray, Add, E&xit, Exit
Menu, Tray, Default, &Show
Menu, Tray, NoStandard

#Include assets\JSON_ToObj.ahk
#Include assets\Webapp.ahk

__Webapp_GuiSize:
	global __WebappH, __WebappW
	__WebappH := A_GuiHeight
	__WebappW := A_GuiWidth
	RepositionGui()
return

RepositionGui() {
	global vSearch
	if (vSearch) {
		GuiControlGet, vPos, __Webapp_:Pos, SearchBox
		GuiControl, __Webapp_:Show, SearchBox
		GuiControl, __Webapp_:Move, SearchBox, W%__WebappW%
		webH := __WebappH - vPosH
	}
	else {
		GuiControl, __Webapp_:Hide, SearchBox
		webH := __WebappH
	}
	GuiControl, __Webapp_:Move, __Webapp_wb, Y%vPosH% W%__WebappW% H%webH%
}

__Webapp_AppStart:
;<< Header End >>

;             not focusable
Gui __Webapp_:+E0x08000000 +AlwaysOnTop -MaximizeBox -MinimizeBox ; +E0x40000 +ToolWindow ;  -Caption
OnMessage(0x112, "WM_SYSCOMMAND")

WM_SYSCOMMAND(wParam)
{
	global vVisible
    if (wParam = 0xF060 and vVisible) ; SC_CLOSE hide instead of closing
    {
        Hide()
        return 0
    }
}

; Variable containing the current state
vVisible := false
; Variable containing the searching state
vSearch := false
; Search Handler Semaphore (avoid multiple instances running)
vSearchSem := 1
vSearchInput := ""
; Save clipboard contents
clipSaved =
bClipSaved := False

; Change App name at run-time
setAppName("Emoji Keyboard")

; Our custom protocol's url event handler
app_call(args) {

	;MsgBox %args%
	param := SubStr(args, 6)
	if SubStr(args, 1, 5) = "send/"
		Send(param)
}

; Function to run when page is loaded
app_page(NewURL) {
}

Gui __Webapp_:Hide

; Change Hotkey here
Capslock::
	global vVisible
	if(vVisible){
		vVisible := false
		Hide()
		Return
	}
	Show()
Return

; Functions to be called from the html/js source
Exit() {
	ExitApp
}
Credits() {
	Run, https://github.com/romligCH/emoji-keyboard
}
Reload() {
	Reload
}

Send(t) {
	SetTimer, RestoreClipboard, Off
	global clipSaved, bClipSaved, vSearch
	if (vSearch) {
		Gui __Webapp_:Hide
	}
	if(not bClipSaved) {
		clipSaved := ClipboardAll
		bClipSaved := True
	}
	Clipboard := t
	Sleep, 10
	Send, ^v
	SetTimer, RestoreClipboard, 200
	if (vSearch) {
		Gui __Webapp_:Show
	}
}
RestoreClipboard() {
	global clipSaved, bClipSaved
	SetTimer, RestoreClipboard, Off
	Clipboard := clipSaved
	clipSaved =
	bClipSaved := False
}

Show() {
	global vVisible, vSearch
	vVisible := true
	Gui __Webapp_:Show, NA
	if (vSearch) {
		GuiControl, __Webapp_:Focus, SearchBox
	}
}
Hide() {
	global vVisible, vSearch
	vVisible := false
	Gui __Webapp_:Hide
}
Toggle() {
	global vVisible
	if(vVisible){
		Hide()
	}
	else{
		Show()
	}
}

Ready() {
	global j
	getDOM().document.ahk.setKeymap(j.keymap)
	getDOM().document.ahk.setOS(A_OSVersion)
}

SetTitle(t) {
	Gui __Webapp_:Show, NA, %t%
}

SearchChange() {
	GuiControlGet, str, __Webapp_:, SearchBox
	getDOM().document.ahk.setSearchText(str)
}

ToggleSearch() {
	global vSearch
	if vSearch
		SetSearch(false)
	else
		SetSearch(true)
}
SetSearch(s) {
	global vSearch
	oldSearch := vSearch
	vSearch := s
	if (oldSearch and !s) {
		RepositionGui()
		Gui __Webapp_:Show
		Gui __Webapp_:+E0x08000000
		Send !{Esc}
		getDOM().document.ahk.setSearch(false)
	}
	If (!oldSearch and s) {
		RepositionGui()
		Gui __Webapp_:-E0x08000000
		Gui __Webapp_:Show
		getDOM().document.ahk.setSearch(true)
		GuiControl, __Webapp_:Focus, SearchBox
	}
}

#If vVisible
; Corresponding keys                    		;	US	CH
SC029::getDOM().document.ahk.input(41)   		;	`	§
SC002::getDOM().document.ahk.input(2)    		;	1	1
SC003::getDOM().document.ahk.input(3)   		;	2	2
SC004::getDOM().document.ahk.input(4)   		;	3	3
SC005::getDOM().document.ahk.input(5)   		;	4	4
SC006::getDOM().document.ahk.input(6)   		;	5	5
SC007::getDOM().document.ahk.input(7)   		;	6	6
SC008::getDOM().document.ahk.input(8)   		;	7	7
SC009::getDOM().document.ahk.input(9)   		;	8	8
SC00A::getDOM().document.ahk.input(10)   		;	9	9
SC00B::getDOM().document.ahk.input(11)   		;	0	0
SC00C::getDOM().document.ahk.input(12)   		;	-	'
SC00D::getDOM().document.ahk.input(13)   		;	=	^
+SC029::getDOM().document.ahk.input(41, True)  	;	`	§
+SC002::getDOM().document.ahk.input(2, True)	;	1	1
+SC003::getDOM().document.ahk.input(3, True)	;	2	2
+SC004::getDOM().document.ahk.input(4, True)	;	3	3
+SC005::getDOM().document.ahk.input(5, True)	;	4	4
+SC006::getDOM().document.ahk.input(6, True)	;	5	5
+SC007::getDOM().document.ahk.input(7, True)	;	6	6
+SC008::getDOM().document.ahk.input(8, True)	;	7	7
+SC009::getDOM().document.ahk.input(9, True)	;	8	8
+SC00A::getDOM().document.ahk.input(10, True)	;	9	9
+SC00B::getDOM().document.ahk.input(11, True)	;	0	0
+SC00C::getDOM().document.ahk.input(12, True)	;	-	'
+SC00D::getDOM().document.ahk.input(13, True)	;	=	^
Tab::ToggleSearch()
+Tab::ToggleSearch()
#If vVisible and vSearch
^Backspace::GuiControl, __Webapp_:, SearchBox,  ; clear seach
#If vVisible and !vSearch
; Corresponding keys                    		;	US	CH
;SC001::getDOM().document.ahk.input(1)   		;	ESC	ESC
;SC03B::getDOM().document.ahk.input(59)   		;	F1	F1
;SC03C::getDOM().document.ahk.input(60)   		;	F2	F2
;SC03D::getDOM().document.ahk.input(61)   		;	F3	F3
;SC03E::getDOM().document.ahk.input(62)   		;	F4	F4
;SC03F::getDOM().document.ahk.input(63)   		;	F5	F5
;SC040::getDOM().document.ahk.input(64)   		;	F6	F6
;SC041::getDOM().document.ahk.input(65)   		;	F7	F7
;SC042::getDOM().document.ahk.input(66)   		;	F8	F8
;SC043::getDOM().document.ahk.input(67)   		;	F9	F9
;SC044::getDOM().document.ahk.input(68)   		;	F10	F10
;SC057::getDOM().document.ahk.input(87)   		;	F11	F11
;SC058::getDOM().document.ahk.input(88)   		;	F12	F12
SC010::getDOM().document.ahk.input(16)   		;	q	q
SC011::getDOM().document.ahk.input(17)   		;	w	w
SC012::getDOM().document.ahk.input(18)   		;	e	e
SC013::getDOM().document.ahk.input(19)   		;	r	r
SC014::getDOM().document.ahk.input(20)   		;	t	t
SC015::getDOM().document.ahk.input(21)   		;	y	z
SC016::getDOM().document.ahk.input(22)   		;	u	u
SC017::getDOM().document.ahk.input(23)   		;	i	i
SC018::getDOM().document.ahk.input(24)   		;	o	o
SC019::getDOM().document.ahk.input(25)   		;	p	p
SC01A::getDOM().document.ahk.input(26)   		;	[	èü
SC01B::getDOM().document.ahk.input(27)   		;	]	¨
SC01E::getDOM().document.ahk.input(30)   		;	a	a
SC01F::getDOM().document.ahk.input(31)   		;	s	s
SC020::getDOM().document.ahk.input(32)   		;	d	d
SC021::getDOM().document.ahk.input(33)   		;	f	f
SC022::getDOM().document.ahk.input(34)   		;	g	g
SC023::getDOM().document.ahk.input(35)   		;	h	h
SC024::getDOM().document.ahk.input(36)   		;	j	j
SC025::getDOM().document.ahk.input(37)   		;	k	k
SC026::getDOM().document.ahk.input(38)   		;	l	l
SC027::getDOM().document.ahk.input(39)   		;	;	éö
SC028::getDOM().document.ahk.input(40)   		;	'	àä
SC02B::getDOM().document.ahk.input(43)   		;	\	$
SC056::getDOM().document.ahk.input(86)   		;	\	<
SC02C::getDOM().document.ahk.input(44)   		;	z	y
SC02D::getDOM().document.ahk.input(45)   		;	x	x
SC02E::getDOM().document.ahk.input(46)   		;	c	c
SC02F::getDOM().document.ahk.input(47)   		;	v	v
SC030::getDOM().document.ahk.input(48)   		;	b	b
SC031::getDOM().document.ahk.input(49)   		;	n	n
SC032::getDOM().document.ahk.input(50)   		;	m	m
SC033::getDOM().document.ahk.input(51)   		;	,	,
SC034::getDOM().document.ahk.input(52)   		;	.	.
SC035::getDOM().document.ahk.input(53)   		;	/	-
+SC010::getDOM().document.ahk.input(16, True)	;	q	q
+SC011::getDOM().document.ahk.input(17, True)	;	w	w
+SC012::getDOM().document.ahk.input(18, True)	;	e	e
+SC013::getDOM().document.ahk.input(19, True)	;	r	r
+SC014::getDOM().document.ahk.input(20, True)	;	t	t
+SC015::getDOM().document.ahk.input(21, True)	;	y	z
+SC016::getDOM().document.ahk.input(22, True)	;	u	u
+SC017::getDOM().document.ahk.input(23, True)	;	i	i
+SC018::getDOM().document.ahk.input(24, True)	;	o	o
+SC019::getDOM().document.ahk.input(25, True)	;	p	p
+SC01A::getDOM().document.ahk.input(26, True)	;	[	èü
+SC01B::getDOM().document.ahk.input(27, True)	;	]	¨
+SC01E::getDOM().document.ahk.input(30, True)	;	a	a
+SC01F::getDOM().document.ahk.input(31, True)	;	s	s
+SC020::getDOM().document.ahk.input(32, True)	;	d	d
+SC021::getDOM().document.ahk.input(33, True)	;	f	f
+SC022::getDOM().document.ahk.input(34, True)	;	g	g
+SC023::getDOM().document.ahk.input(35, True)	;	h	h
+SC024::getDOM().document.ahk.input(36, True)	;	j	j
+SC025::getDOM().document.ahk.input(37, True)	;	k	k
+SC026::getDOM().document.ahk.input(38, True)	;	l	l
+SC027::getDOM().document.ahk.input(39, True)	;	;	éö
+SC028::getDOM().document.ahk.input(40, True)	;	'	àä
+SC02B::getDOM().document.ahk.input(43, True)	;	\	$
+SC056::getDOM().document.ahk.input(86, True)	;	\	<
+SC02C::getDOM().document.ahk.input(44, True)	;	z	y
+SC02D::getDOM().document.ahk.input(45, True)	;	x	x
+SC02E::getDOM().document.ahk.input(46, True)	;	c	c
+SC02F::getDOM().document.ahk.input(47, True)	;	v	v
+SC030::getDOM().document.ahk.input(48, True)	;	b	b
+SC031::getDOM().document.ahk.input(49, True)	;	n	n
+SC032::getDOM().document.ahk.input(50, True)	;	m	m
+SC033::getDOM().document.ahk.input(51, True)	;	,	,
+SC034::getDOM().document.ahk.input(52, True)	;	.	.
+SC035::getDOM().document.ahk.input(53, True)	;	/	-
#If