Jump to content

Get Commands bound to Key


Bonsai

Recommended Posts

Well as you said these seems to be for functions:

getFunctionsBoundToKey  
getKeyBoundToFunction 

But since they return a table (with strings I assume) it might work for bound commands as well, try the wiki example if you haven't done it yet and see what it outputs. Admin panel for example (default key: 'P') can be accessed by the command '/admin' as well, so if this works you should be able to see that in the output.

function output() 
    outputChatBox("Hi") 
end 
bindKey("f2","down",output) 
  
local keyTable = { "mouse1", "mouse2", "mouse3", "mouse4", "mouse5", "mouse_wheel_up", "mouse_wheel_down", "arrow_l", "arrow_u", 
 "arrow_r", "arrow_d", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", 
 "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "num_0", "num_1", "num_2", "num_3", "num_4", "num_5", 
 "num_6", "num_7", "num_8", "num_9", "num_mul", "num_add", "num_sep", "num_sub", "num_div", "num_dec", "F1", "F2", "F3", "F4", "F5", 
 "F6", "F7", "F8", "F9", "F10", "F11", "F12", "backspace", "tab", "lalt", "ralt", "enter", "space", "pgup", "pgdn", "end", "home", 
 "insert", "delete", "lshift", "rshift", "lctrl", "rctrl", "[", "]", "pause", "capslock", "scroll", ";", ",", "-", ".", "/", "#", "\\", "=" } 
  
addCommandHandler("gakf",function() 
    for _,i in ipairs(keyTable)do --loop through keyTable 
        for _,v in ipairs(getFunctionsBoundToKey(i))do --loop through the key bounded functions 
            outputChatBox(i..":"..v) --output the keyname and the function bound to it 
        end 
    end 
end) 

Link to comment
  • 3 years later...

Do you know how to get names of functions. There are numbers like objects data. The letter keys are not returned. I mean, I need a list like in menu -> binds. This function is promising but doesn't work for me.

I mean, I'm asking because want to use something like this:

function playerPressedKey( button, press )
    local boundKey = getKeyBoundToFunction( 'horn' );
    if button == boundKey then   
        if ( press ) then
            ACTION = false
            outputDebugString( "You pressed the "..button.." key!" )
        end
    end    
end
addEventHandler( "onClientKey", root, playerPressedKey )

which should work that way - I use horn to speed up ped's slow walking on the street. But don't know where's horn binded.

Edited by Salem
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...