Page 1 of 1

Q: ctrl, shift and alt on a button tool?

Posted: Thu Sep 27, 2012 5:08 am
by Breinmeester
Hello,

I'm writing a script which i want executed at the press of a button, so i included it in the _tool_list with the 'button' mark.

Here's my question: I want the script to act differently if alt, shift or ctrl are held. How can i accomplish that?

So for example, i have the script included in the _tool_list like this:
button lm_scriptname k

Now i want it to do different things when you press [ctrl] + [k], [alt] + [k] and [shift] + [k].

Ive tried:

Code: Select all

function lm_scriptname:OnKeyDown(moho, keyEvent)
	if (keyEvent.altKey) then
		print('Alt down')
		return
	end
end
but it doesn't work.

More importantly, if i press [k] the script runs, but if i press [ctrl] + [k], [alt] + [k] or [shift] + [k] it doesn't.

Any advice anyone? Thanks!

Re: Q: ctrl, shift and alt on a button tool?

Posted: Sun Oct 21, 2012 2:05 pm
by PhilIcare
Hi

The shortcut for your tool is "k". So it runs when "k" is pressed. "[Alt]+k" is another shortcut, not equal to "k", I guess.

The issue would be :

Code: Select all

button lm_scriptname    k
button lm_scriptname    ALT+k    // how to specify it? 
button lm_scriptname    K
button lm_scriptname    CTRL+k  // idem
I don't know if it's possible.

Another issue would be :

- One key for the tool (let's say "k")
- One another to operate (let's say "d" like "do", though it could be the same, ie "k")

Code: Select all

tool  lm_scriptname    k

Code: Select all

function LM_ScripName:OnKeyDown(moho, ev)
  if ( ev.key ~= "d" and ev.key ~= "k") then
    return 
  end
  if ( ev.keyCtrl ) then
    -- do your stuff
  elseif ( ev.keyAlt ) then
    -- do your stuff
  -- and so on
  end
end
Hope it helps...

Phil
PS : apologies for my ugly english