Page 1 of 1

KEY_ESCAPE

Posted: Wed Jun 26, 2024 11:04 pm
by MehdiZangenehBar
I need to know when escape key pressed on keyboard, but the keycode will return -51.0 and 27.0, which is not the constant LM.GUI.KEY_ESCAPE = -2

Code: Select all

-- **************************************************
-- General information about this script
-- **************************************************

ScriptName = "Test_Script"
Test_Script = {}

-- **************************************************
-- Events
-- **************************************************

function Test_Script:OnMouseDown(moho, mouseEvent)
end

function Test_Script:OnKeyDown(moho, keyEvent)
	print(tostring(keyEvent.keyCode))
	if keyEvent.keyCode == LM.GUI.KEY_ESCAPE then
		print('Escape key pressed.')
	end
end

Re: KEY_ESCAPE

Posted: Wed Jun 26, 2024 11:36 pm
by KuzKuz
Use if keyEvent.keyCode == 27 or keyEvent.keyCode == -51 then

Re: KEY_ESCAPE

Posted: Thu Jun 27, 2024 2:22 pm
by MehdiZangenehBar
KuzKuz wrote: Wed Jun 26, 2024 11:36 pm Use if keyEvent.keyCode == 27 or keyEvent.keyCode == -51 then
Wierd!
Another question is: why it will be triggered twice?

Re: KEY_ESCAPE

Posted: Thu Jun 27, 2024 2:52 pm
by KuzKuz
If I remember correctly, one keyCode is for Windows, the other for Mac. I used this in MR Curve Tool.