Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Input problems — Gideros Forum

Input problems

rrraptorrrraptor Member
edited May 2020 in General questions
Hello, Im trying to create a TextBox object, but I have a strange problem.
Everything works well with the Latin alphabet, but when it comes to the Cyrillic alphabet a strange symbol getting added at the end.
Gif:

The symbol itself: �
Dec: 65533
HEX: U+FFFD
Any suggestions?)

Input handle code:
local function append(tf, text)
	tf:setText(tf:getText() .. text)
end
local UTF = utf8.char
 
function TextBox:input(real, actual)
	if actual == KeyCode.BACKSPACE then 
		local str = self.label:getText()
		self.label:setText(str:sub(1,str:len()-1))
	else
		if real == 1025 then -- "ё"  special case
			local char = ""
			if self.isShiftPressed then 
				char = UTF(1025)
			else
				char = UTF(1105)
			end
			append(self.label, char)
		-- Latin & Cyrillic alphabet codes
		elseif (real >= 65 and real <= 90) or (real >= 1040 and real <= 1071) then 
			local char = ""
			if self.isShiftPressed then
				char = UTF(real) -- upper case
			else
				char = UTF(real+32) -- lower case
			end
			append(self.label, char)
		elseif real <= 9600 then -- to prevent appending most of functional code like F1,F2,...,HOME,END,TAB etc.
			append(self.label, UTF(real))
		end
	end
	self:updatePos() -- update cursor position
end
--
function TextBox:keyDown(e)
	if self.line:isVisible() then
		--print(e.keyCode, e.realCode)
		if e.keyCode == KeyCode.SHIFT then 
			self.isShiftPressed = true
		elseif e.keyCode == KeyCode.CTRL then 
			self.isCtrlPressed = true
		end
		self.activeKey = e.keyCode
		self.activeRKey = e.realCode
		self.counter = 0
		self:input(self.activeRKey,self.activeKey)
		self.holdTimer:reset()
		self.holdTimer:start()
	end
end
--
function TextBox:keyUp(e)
	if self.line:isVisible() then 
		if e.keyCode == self.activeKey then
			self.activeKey = nil
			self.holdTimer:stop()
		elseif e.keyCode == KeyCode.SHIFT then 
			self.isShiftPressed = false
		elseif e.keyCode == KeyCode.CTRL then 
			self.isCtrlPressed = false
		end
		if self.activeRKey == e.realCode then 
			self.activeRKey = nil
			self.holdTimer:stop()
		end
	end
end

Project attached.
bug.gif
215 x 220 - 539K
rar
rar
TextBoxTest.rar
486K

Comments

Sign In or Register to comment.