KEY_ESCAPE

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

KEY_ESCAPE

Post 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
User avatar
KuzKuz
Posts: 611
Joined: Mon Aug 19, 2013 5:12 pm
Location: Ukraine

Re: KEY_ESCAPE

Post by KuzKuz »

Use if keyEvent.keyCode == 27 or keyEvent.keyCode == -51 then
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: KEY_ESCAPE

Post 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?
User avatar
KuzKuz
Posts: 611
Joined: Mon Aug 19, 2013 5:12 pm
Location: Ukraine

Re: KEY_ESCAPE

Post by KuzKuz »

If I remember correctly, one keyCode is for Windows, the other for Mac. I used this in MR Curve Tool.
Post Reply