Check Player Mouse Pos

I want to make my afk system use mouse position. I am not really sure how I would do this or explain it but basically it gets the players mouse position and if it hasnt changed after a certain amount of time it will continue to check but when it changes it activated a concommand. I really have no idea where to even start on this as I am a but confused on how it would actually work. Can anyone offer some code snippets? This would need to be clientside checking of course.

Heres my afk timer if anyone would like one.
[lua]
AwayTime = 300

function AFK( ply )
for _, v in pairs( player.GetAll()) do
local a = (v:GetNWInt(“LA”) + AwayTime) - CurTime()
if a <= 0 then
v:SetNWBool(“AFK”, true)
if v:GetNWBool(“AFKN”) == true then
for k, ply in pairs( player.GetAll( ) ) do
v:SetNWBool(“AFKN”, false)
end
end
end
end
end
timer.Create(“AFK_timer”, 1, 0, AFK)

function ResetAFK( ply )
ply:SetNWInt(“LA”, CurTime())
ply:SetNWBool(“AFK”, false)
ply:SetNWBool(“AFKN”, true)
end
concommand.Add( “ResetAFK”, ResetAFK )
[/lua]

Here’s how I’d do it:

[lua]local AwayTime = 300

function AFK()
for _,v in ipairs( player.GetAll() ) do

	if !v.LastPos then v.LastPos = v:GetPos() end
	if !v.LastAngles then v.LastAngles = v:EyeAngles() end
	
	if v:GetPos() == v.LastPos and v:EyeAngles() == v.LastAngles then
	
		local last_afk = v:GetNWInt("LastAFK")
		if last_afk == 0 then v:SetNWInt("LastAFK",CurTime()) end
		v:SetNWInt("AFKN",CurTime() - v:GetNWInt("LastAFK"))
	
	else
		
		v:SetNWInt("LastAFK",0)
		v:SetNWInt("AFKN",0)
		
	end
	
	v.LastPos = v:GetPos()
	v.LastAngles = v:EyeAngles()
end

end
hook.Add(“Think”,“CheckAFK”,AFK)[/lua]

You think using a think hook is a good idea? Why not throw it on a timer of one second or something?

Hmm it seems to set them to not afk if they get moved, is there a way to make it so only if they move their mouse it triggers?

gui.MousePos() isn’t much good, as it changes even if gmod doesn’t have window focus, so someone could be AFK in game but still be at their computer and a system using the mouse position wouldn’t be any the wiser.

Alright thanks for the tip, guess I will go back to using keypresses and such.