input.IsKeyDown() + Think.

How can i improve this code:

[lua]
hook.Add(“Think”, “keyboardevents”, function()
if input.IsMouseDown(MOUSE_4) then
print(“you pushed mouse4”)
else
print(“you let go of mouse4”)
end
end)
[/lua]

So that it only prints once each time?

Probrably something like this,

[lua]
– not what i posted earlier.
local b= false;
hook.Add(“Think”, “keyboardevents”, function()
if input.IsMouseDown(MOUSE_4) and (not b) then
b= true;
print(“you pushed mouse4”)
elseif (not input.IsMouseDown(MOUSE_4)) and b then
b= false;
print(“you let go of mouse4”)
end
end)[/lua]

sweet thanks, let me give it a try real quick

add a global check value like this
[lua]
isMouse4Down = false
hook.Add(“Think”, “keyboardevents”, function()
if input.IsMouseDown(MOUSE_4) and !isMouse4Down then
print(“mouse 4 down”)
isMouse4Down = true
elseif !input.IsMouseDown(MOUSE_4) and isMouse4Down then
print(“mose 4 released”)
isMouse4Down = false
end
end )

[/lua]
should fire once on each account, i’m using something similar for a spawn menu, this snip is untested but it’s mostly the idea.

I got :ninja:ed!, but i’ll just leave this here anyway.




you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4
you pushed mouse4
you let go of mouse4


[lua]
local b= false;
hook.Add(“Think”, “keyboardevents”, function()
if input.IsMouseDown(MOUSE_4) and (not b) then
b= true;
print(“you pushed mouse4”)
elseif (not input.IsMouseDown(MOUSE_4)) and b then
b= false;
print(“you let go of mouse4”)
end
end)
[/lua]

Stupid mistake, I’m sorry.
This should do though.

actually newbees didn’t work, but fantys worked perfectly! thanks bro.

Thanks to everyone who posted in the thread though.

wait, it didn’t work after i edited it? :wtc:

I actually didnt test after you edited it haha I just went with fanty’s code since it worked first try :stuck_out_tongue: I can test if you would like?

No nevermind, I was just suprised when you said that because it really should work.

Oh ha, understandable.