2007-04-16 17:15:22 +00:00
|
|
|
|
|
|
|
AddCSLuaFile( "cl_init.lua" )
|
|
|
|
AddCSLuaFile( "shared.lua" )
|
|
|
|
|
|
|
|
include('shared.lua')
|
2007-10-25 10:36:01 +00:00
|
|
|
include('remap.lua')
|
2007-04-16 17:15:22 +00:00
|
|
|
|
2007-10-25 10:36:01 +00:00
|
|
|
ENT.WireDebugName = "Wired Keyboard"
|
2007-04-16 17:15:22 +00:00
|
|
|
ENT.OverlayDelay = 0
|
|
|
|
|
|
|
|
local MODEL = Model("models/jaanus/wiretool/wiretool_input.mdl")
|
|
|
|
|
|
|
|
function ENT:Initialize()
|
|
|
|
self.Entity:SetModel( MODEL )
|
|
|
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
|
|
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
|
|
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
|
|
|
|
|
|
|
self.On = {}
|
|
|
|
self.Outputs = Wire_CreateOutputs(self.Entity, { "Memory" })
|
|
|
|
|
2007-10-25 10:36:01 +00:00
|
|
|
for i = 0,223 do
|
2007-04-16 17:15:22 +00:00
|
|
|
self.On[i] = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
self.Buffer = {}
|
|
|
|
for i = 0,31 do
|
|
|
|
self.Buffer[i] = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
self.InUse = false
|
|
|
|
self:SetOverlayText( "Keyboard - not in use" )
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function ENT:ReadCell( Address )
|
|
|
|
if (Address >= 0) && (Address < 32) then
|
|
|
|
return self.Buffer[Address]
|
2007-10-25 10:36:01 +00:00
|
|
|
elseif (Address >= 32) && (Address < 256) then
|
2007-11-25 12:43:32 +00:00
|
|
|
if (self.On[Address-32]) then
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
2007-04-16 17:15:22 +00:00
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:WriteCell( Address, value )
|
2007-10-25 10:36:01 +00:00
|
|
|
if (Address >= 0) && (Address < 256) then
|
2007-04-16 17:15:22 +00:00
|
|
|
self:Switch(false,value)
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Use(pl)
|
|
|
|
if (!self.InUse) then
|
|
|
|
self.InUse = true
|
2007-10-25 10:36:01 +00:00
|
|
|
self:SetOverlayText( "Keyboard - In use by " .. pl:GetName() )
|
|
|
|
pl:ConCommand("wire_keyboard_on "..self:EntIndex())
|
2007-04-16 17:15:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-10-25 10:36:01 +00:00
|
|
|
//=============================================================================
|
|
|
|
// Switch key state to ON/OFF
|
|
|
|
//=============================================================================
|
2007-04-16 17:15:22 +00:00
|
|
|
|
|
|
|
function ENT:Switch( on, key )
|
|
|
|
if (!self.Entity:IsValid()) then return false end
|
|
|
|
|
|
|
|
if (key == -1) then
|
|
|
|
self.Buffer[0] = 0
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
self.On[ key ] = on
|
|
|
|
|
|
|
|
if ( on ) then
|
|
|
|
self.Buffer[0] = self.Buffer[0] + 1
|
|
|
|
self.Buffer[self.Buffer[0]] = key
|
2007-04-23 20:20:48 +00:00
|
|
|
Wire_TriggerOutput(self.Entity, "Memory", key)
|
2007-04-16 17:15:22 +00:00
|
|
|
else
|
2007-10-25 10:36:01 +00:00
|
|
|
Wire_TriggerOutput(self.Entity, "Memory", 0)
|
2007-04-16 17:15:22 +00:00
|
|
|
for i = 1,self.Buffer[0] do
|
|
|
|
if (self.Buffer[i] == key) then
|
|
|
|
self.Buffer[0] = self.Buffer[0] - 1
|
|
|
|
for j = i,self.Buffer[0] do
|
|
|
|
self.Buffer[j] = self.Buffer[j+1]
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2007-10-25 10:36:01 +00:00
|
|
|
//=============================================================================
|
|
|
|
// Keyboard turning ON/OFF
|
|
|
|
//=============================================================================
|
2007-04-16 17:15:22 +00:00
|
|
|
|
2007-10-25 10:36:01 +00:00
|
|
|
KeyBoardPlayerKeys = {}
|
2007-04-16 17:15:22 +00:00
|
|
|
|
|
|
|
function Wire_KeyOff ( pl, cmd, args )
|
|
|
|
local ent = ents.GetByIndex( KeyBoardPlayerKeys[pl:EntIndex()] )
|
|
|
|
if (ent) && (ent:IsValid()) && (ent.InUse) then
|
|
|
|
ent.InUse = false
|
|
|
|
ent:SetOverlayText( "Keyboard - not in use" )
|
|
|
|
end
|
|
|
|
KeyBoardPlayerKeys[pl:EntIndex()] = -1
|
|
|
|
|
2007-10-25 10:36:01 +00:00
|
|
|
pl:ConCommand("wire_keyboard_releaseinput")
|
2007-04-16 17:15:22 +00:00
|
|
|
pl:PrintMessage(HUD_PRINTTALK,"Virtual keyboard turned off\n")
|
|
|
|
end
|
2007-10-25 10:36:01 +00:00
|
|
|
concommand.Add("wire_keyboard_off", Wire_KeyOff)
|
|
|
|
|
|
|
|
function Wire_KeyOn( pl, cmd, args )
|
|
|
|
KeyBoardPlayerKeys[pl:EntIndex()] = args[1]
|
|
|
|
|
|
|
|
pl:ConCommand("wire_keyboard_blockinput")
|
2007-10-27 07:28:18 +00:00
|
|
|
pl:PrintMessage(HUD_PRINTTALK,"Wired keyboard turned on - press ALT to exit the mode!\n")
|
2007-10-25 10:36:01 +00:00
|
|
|
end
|
|
|
|
concommand.Add("wire_keyboard_on", Wire_KeyOn)
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// Key press/release hook handlers
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
function Wire_KeyPressed( pl, cmd, args )
|
|
|
|
local key = tonumber(args[2])
|
|
|
|
|
|
|
|
if (!KeyBoardPlayerKeys[pl:EntIndex()]) then return end
|
|
|
|
local ent = ents.GetByIndex( KeyBoardPlayerKeys[pl:EntIndex()] )
|
|
|
|
if (!ent) || (!ent:IsValid()) || (!ent.InUse) then return end
|
|
|
|
|
2007-10-27 07:28:18 +00:00
|
|
|
if (key == KEY_RALT) || (key == KEY_LALT) then
|
2007-10-25 10:36:01 +00:00
|
|
|
pl:ConCommand("wire_keyboard_off")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
//Get normalized/ASCII key
|
|
|
|
local nkey
|
|
|
|
if (Keyboard_ReMap[key]) then nkey = Keyboard_ReMap[key]
|
|
|
|
else nkey = 0 end
|
|
|
|
|
|
|
|
if (ent.On[21] == true) then
|
|
|
|
if (Keyboard_CaseReMap[string.char(nkey)]) then
|
|
|
|
nkey = string.byte(Keyboard_CaseReMap[string.char(nkey)])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (args[1] == "press") then
|
|
|
|
if (key == KEY_LCONTROL) || (key == KEY_RCONTROL) then ent:Switch(true,16) end
|
|
|
|
if (key == KEY_LSHIFT) || (key == KEY_RSHIFT) then ent:Switch(true,21) end
|
|
|
|
|
|
|
|
ent:Switch(true,nkey)
|
|
|
|
else
|
|
|
|
if (key == KEY_LCONTROL) || (key == KEY_RCONTROL) then ent:Switch(false,16) end
|
|
|
|
if (key == KEY_LSHIFT) || (key == KEY_RSHIFT) then ent:Switch(false,21) end
|
|
|
|
|
|
|
|
ent:Switch(false,nkey)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
concommand.Add("wire_keyboard_press", Wire_KeyPressed)
|