Jump to content

M to click


Kevin_Linden

Recommended Posts

Don't you have to close it? I don't really script well in lua but in php i have to. So I have this so far.

mousekey.lua

bindKey( "m", mouse)
  function mouse()
     showCursor( not isCursorShowing() )
  end
)

meta.xml

<meta>
   <info author='Antibird and Kevin' version='1' name='mousekey' type='script' />
   <script src='mousekey.lua' type='client' />
</meta>

Link to comment

you need more javascript ;) as javascript also has events working like lua :) (especially in jquery)

so bindKey has 3 parameters:

1st - the key

2nd - the state of key that trigger function ("down" mean when you press key down, "up" (not supported yet) when you release it, "both" (not supported yet))

3rd - the function that handles that keypress

you can do

function function_showing_cursor(player, key, state)
-- something there
end

bindKey("m", "down", function_showing_cursor)

or

bindKey("m", "down", function(player, key,state)
-- something there
end)
)

(notice on the 1st example - when typing function that handles your keypress, you dont pass any arguments in (), it should be without () there - it could be your common mistake - im talking from view php programmer ;))

hope i helped you to understand :)

Edited by Guest
Link to comment

bindKey has 3 arguments. the first is the key as a string, so if you want to bind something to the m key you need to write "m"

the second argument is the state of the key. if you want something to happen when the user presses the button down then you use "down", but there are cases when you want something to happen when the user releases a key, that would be "up", that's especially essential for displays that should be shown while the user holds a specific key.

and the third argument is a function, it doesn't matter if you point to a previously defined function or define that function right there. in thus case the function has been defined directly in there

bindKey( "m", "down",
function()
showCursor( not isCursorShowing() )
end
)

but this would work as well:

function thisIsOurFunction()
showCursor( not isCursorShowing() )
end
bindKey( "m", "down", thisIsOurFunction )

just with the difference that we point to a a function, bindKey will then know what function to find

then finally

showCursor( not isCursorShowing() )

is doing the magic. depending on if the mouse cursor is currently showing or hidden it sets the mouse cursors showing state to the opposite. shows the cursor when it's not showing and hides it if it is already showing.

EDIT: NINJAS!!!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...