Ways of binding without using the console

Hey, i need a way of binding a console command to the LEFTARROW( thats the key name in gmod aswell ) button wihout the client having to do it. any help?

use on key press http://wiki.garrysmod.com/?title=Gamemode.KeyPress and for a list of keys
http://wiki.garrysmod.com/?title=IN_KEYS

I have tried that it doesnt work as the player then needs to bind LEFTARROW to eg IN_LEFT. IT needs to be done without the player doing it.

I think IN_LEFT is like pressing A not pressing left arrow key and i cant seem to find the arrow key name hold on i will try and track it down

[editline]07:02PM[/editline]

OK i cant seem to find it have you tryed IN_LEFTARROW

You need to use the ‘input.IsKeyDown’ function if you want to use the arrow keys.

O Thanks I learned from this

It’s KEY_LEFT. IN_LEFT only triggers if the player has bound the arrowkeys to look around instead of the mouse.

Thanks but im not quite sure how that works this what ive got

lua:
[lua]
function Keys(ply)

KeyEvents = {}

for KEY_LEFT=1, 130 do

if( input.IsKeyDown(KEY_LEFT)) then
if(KeyEvents[KEY_LEFT]==1) then
RunConsoleCommand( “LEFT_C” )
end
end
end
end
[/lua]

Any help?

I don’t think anyone knows what you’re trying to do there. Try this one…

[lua]
– somewhere else before the think hook
local pressed = false;

– your think hook
if( input.IsKeyDown( KEY_LEFT ) ) then

if( not pressed ) then
	
	pressed = true;
	
	-- do stuff on press
	
end

else

if( pressed ) then
	
	pressed = false;
	
	-- do stuff on release
	
end

end
[/lua]

I just tried that andi get this error



Hook 'CLeftBind' Failed: ZeldaLegends/gamemode/init.lua:79: attempt to index global 'input' (a nil value)


Lua:
[lua]
function CLEFTKEY(ply)
if( input.IsKeyDown( KEY_LEFT ) ) then

if( not pressed ) then
	
	pressed = true;
	
	if ply:Team() == LINK then
	ply:StripWeapons()
	ply:Give( "weapon_crossbow" )
	
end

else

if( pressed ) then
	
	pressed = false;
	
		return end
end

end
end
hook.Add( “PlayerSpawn”, “CLeftBind”, CLEFTKEY )
[/lua]

its a client function for one…

two…you cant hook it into PlayerSpawn, you have to use a Think, Tick, something that is called often

unless you want this to run when a player spawns…

I love you… Thanks everyone for your help it works now :smiley:

Don’t use Think for this god damn it…

What are you talking about? KeyPress doesn’t work with keyboard keys directly ergo you can’t use arrow keys with it whenever you want.

“You can not use this hook to detect KEY_ keys. This is strictly for IN_ keys.”