Giter VIP home page Giter VIP logo

pmc-keybinds's People

Contributors

pitermcflebor avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pmc-keybinds's Issues

add : RemoveRegisterKey

import.lua :

function RegisterKey(layout, keyname, onpress, onrelease)
    assert(type(layout) == 'string', 'Invalid Lua type, #1 argument expected string')
    assert(type(keyname) == 'string', 'Invalid Lua type, #2 argument expected string')
    assert(type(onpress) == 'function', 'Invalid Lua type, #3 argument expected function')
    assert(onrelease ~= nil and type(onpress) == 'function' or true, 'Invalid Lua type, #4 argument expected function')

    if _KEY_BINDS[layout:upper()] ~= nil and _KEY_BINDS[layout:upper()][keyname:upper()] ~= nil then

        layout, keyname = layout:lower(), keyname:lower()
          -- My Edit --
        local event1 = AddEventHandler(('key:press:%s:%s'):format(layout, keyname), onpress)
        local event2 = AddEventHandler(('key:release:%s:%s'):format(layout, keyname), onrelease)
        TriggerEvent('key:register', layout, keyname,event1,event2)
         -----------


    else
        error"Layour or keyname doesn't exist!"
    end
end

   ------- My Edit --------
function RemoveRegisterKey(layout,key)
    TriggerEvent('key:RemoveRegisterKey', layout,key)
end

AddEventHandler('key:remove', function(e1,e2)
    RemoveEventHandler(e1)
    RemoveEventHandler(e2)
end)

msic.lua :

-- my edit 
AddEventHandler('key:register', function(layout, keyname,event_pressed,event_released)
	if RegisteredKeys[layout] == nil then RegisteredKeys[layout] = {} end
	if RegisteredKeys[layout][keyname] == nil then
		RegisteredKeys[layout][keyname] = {event_pressed=event_pressed,event_released=event_released}
		RegisterKeyMapping(('+keypress %s %s'):format(layout, keyname), 'Binded '..keyname, layout:upper(), keyname:upper())
		print('Adding Key')

	end
end)

-- my edit 
AddEventHandler('key:RemoveRegisterKey', function(layout,key)
	if RegisteredKeys[layout] then 
		if RegisteredKeys[layout][key] then 
			TriggerEvent('key:remove',RegisteredKeys[layout][key].event_pressed , RegisteredKeys[layout][key].event_released)
			RegisteredKeys[layout][key] = nil
		end
	end
end)

And if there is something better it will make it better

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.