


function GHU_KeyInput(_parent,_feedbackFunc,_readOnly)
	local class = Class("GHU_PageLayout");
	
	local parent,feedbackFunc,readOnly = _parent,_feedbackFunc,_readOnly;
	local markedText = "";
	local inputBox;
	local font = GHU_Font();
	
	local STD_TEXT = "\n    \n\n";
	local STD_POS = 3;
	 
	class.SetMarkedText = function(self,text)
		markedText = text or "";	
		
		inputBox:SetText("\n''"..markedText.."''\n");
		inputBox:SetHightlight(STD_POS,STD_POS+strlenutf8(markedText));
		inputBox:SetCursorPosition(STD_POS);
	end
	class.SetFont = function(self,_font)
		font = _font;
		font:ApplyFont(inputBox);
		inputBox:SetHeight(font:GetHeight());
	end
	class.SetOffset = function(self,xOff,yOff) 
		local f = parent;
		if (parent.GetGui) then 
			f = parent:GetGui();
		end
		local h = font:GetHeight();
		inputBox:ClearAllPoints();
		inputBox:SetPoint("BOTTOMRIGHT",f,"TOPLEFT",xOff-h/2,-yOff-h);
	end
	class.Show = function(self)
		
		inputBox:SetFocus();
		inputBox:SetCursorPosition(STD_POS);
		inputBox:Show();
	end
	
	class.Hide = function()
		inputBox:Hide();
	end
	
		
	local f = parent;
	if (parent.GetGui) then 
		f = parent:GetGui();
	end
	inputBox = CreateFrame("Editbox",f);
	inputBox:SetWidth(5);
	inputBox:SetHeight(5);
	inputBox:SetMultiLine(true);
	inputBox:Hide();
	inputBox:SetText(STD_TEXT);
	--inputBox:Se/tFrameLevel(100);
	--inputBox:SetFrameStrata("HIGH");
	
	--GHU_TestBG(inputBox);
	
	-- event handling
	inputBox:SetScript("OnEditFocusLost",function(self)
		class:Hide();
	end);
	inputBox:SetScript("OnCursorChanged",function(self)
		local pos = self:GetCursorPosition();
		local len = strlenutf8(self:GetText()) - strlenutf8(markedText);
		 
		if pos == STD_POS-2 and len == 7 then 
			feedbackFunc("HOME");
		elseif pos == STD_POS-1 and len == 7 then
			feedbackFunc("LEFT");
		elseif pos == STD_POS+1 and len == 7 then
			feedbackFunc("RIGHT");
		elseif pos == STD_POS+2+strlenutf8(markedText) and len == 7 then
			feedbackFunc("END");
		elseif pos == STD_POS-3 and len == 7 then
			feedbackFunc("UP");
		elseif pos == STD_POS+4+strlenutf8(markedText) and len == 7 then
			feedbackFunc("DOWN");
		elseif pos == STD_POS-1 and len == 6 then
			feedbackFunc("BACKWARDS_DELETE");
		elseif pos == STD_POS and len == 6 then
			feedbackFunc("DELETE");
		end
		
		if not(pos == STD_POS) then
			inputBox:SetCursorPosition(STD_POS);
		end
		if not(len == 7) then
			inputBox:SetText(STD_TEXT);
			inputBox:SetCursorPosition(STD_POS);
		end
	end);
	inputBox:SetScript("OnChar",function(self,text) -- OnChar is also fired for each char of a pasted text
		feedbackFunc("CHAR",text);
		self:SetText(STD_TEXT);
		inputBox:SetCursorPosition(STD_POS);
		markedText="";
	end);
	
	inputBox:SetScript("OnEnterPressed",function(self)
		feedbackFunc("ENTER");
	end);
	inputBox:SetScript("OnEscapePressed",function(self)
		feedbackFunc("ESCAPE");
	end);
	inputBox:SetScript("OnSpacePressed",function(self)
		feedbackFunc("SPACE");
	end);
	inputBox:SetScript("OnTabPressed",function(self)
		feedbackFunc("TAB");
	end);
	
	return class;
end