Keyevent value?

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
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 5:29 pm
Location: Sunny Florida
Contact:

Keyevent value?

Post by mkelley »

Idiot question here, but does anyone (Vern? Or maybe Wes now :>) know what value I need to insert here?

if (keyEvent.key == "J") then

Because "J" doesn't work, nor does 'J'. If it's a literal (like "KEY.J") I don't know how to find it so I'd just be guessing.

As for the larger picture, I'm trying to disable the spacebar that welds when translate points is the selected tool (because then I can't use the spacebar for playback with my macros). In *that* code this works:

if (keyEvent.key == ' ') then

which led me to believe my own syntax was correct (which is to say, there ain't no string literal being used there, such as KEY.SPACEBAR).

(Oh, do I hate syntax -- hate taxes in general, but this kind of tax is just ridiculous <bg>)
User avatar
synthsin75
Posts: 10280
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

If I'm not mistaken, that should read:

Code: Select all

if (keyEvent(J) == true) then
I think spacebar is considered a special character, so it is refernced that way instead.

:wink:
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 5:29 pm
Location: Sunny Florida
Contact:

Post by mkelley »

Ah, I guess I really don't know what I'm doing here.

Not sure whether your syntax works or not, but one thing is for sure -- I can't seem to disable the spacebar thingee no matter what I try. More confusing, I can't seem to change the bottom text (where it says "Move Selected Points") which at first glance would seem to indicate that I'm not editing the right tool, but if I remove LM_Translate_Points then translation won't work. But any editing to it seems to be completely ignored.

If you get a chance, Wes, perhaps you could try it. Edit line 24 (where the text is) and see if you can get it to change along the bottom when the (T) tool is selected (on a vector layer). Otherwise I might just not have gotten enough sleep last night.
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 5:29 pm
Location: Sunny Florida
Contact:

Post by mkelley »

Ah, nevermind (unless you're just curious).

I ended up replacing the translate tool with Fazek's and it works as I want (probably better in other ways as well). I had been meaning to do this but this finally got me off my can.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

This won't work.

Code: Select all

if (keyEvent(J) == true) then
Use this:

Code: Select all

local theKey = keyEvent.key
The keyEvent.key is the character that was pressed. You then use that local var "theKey" to compare to the actual key you want pressed to cause something to happen.

Code: Select all

if (theKey == "J") then
   .... do stuff
end
or:

Code: Select all

if (keyEvent.key == "J") then
   .... do stuff
end
EDIT:
Don't forget that keyEvent.key is a "string" even if you press a number. If you want a "real" number when pressing 0-9 then use:

Code: Select all

tonumber(keyEvent.key)
There are some key commands you absolutely can't change or "over ride" in any way using scripting with some of the tools. These keys are "built in" to the application. You can use them for tools but they will still do what they originally did.

I don't know if the space bar is one of those but it might be. I found this mainly with some of the "fkey" commands. Couldn't "deactivate" them.

-vern
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Additional:

Code: Select all

keyEvent.keyCode
Will give you the "ascii" number of the key pressed.

"j" for instance (at least on the mac) returns "106". I am pretty sure they are same regardless of OS but not positive.

-vern
User avatar
synthsin75
Posts: 10280
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

More confusing, I can't seem to change the bottom text (where it says "Move Selected Points") which at first glance would seem to indicate that I'm not editing the right tool
That is because LM's tools reference the 'strings' file for this info. If you kill the previous LM_TranslatePoints.BASE_STR = 2375, then you should be able to change that text.

:wink:
Post Reply