Exemplo n.º 1
0
    /// <summary>
    /// 添加输入设备的事件处理函数
    /// </summary>
    /// <param name="type">设备类型</param>
    /// <param name="code">鼠标类型:0 -> 左键,2 -> 中键,1 -> 右键; 键盘:Key</param>
    /// <param name="handler">处理函数</param>
    public void AddHandler(HardWareEventType type, int code, HardWareEventHandler handler)
    {
        SortedList <int, List <HardWareEventHandler> > list = _hardWareEvents[(int)type];

        if (!list.ContainsKey(code))
        {
            list.Add(code, new List <HardWareEventHandler>());
        }

        List <HardWareEventHandler> handlers = list[code];

        handlers.Add(handler);
    }
Exemplo n.º 2
0
    /// <summary>
    /// 移除事件
    /// </summary>
    /// <param name="type"></param>
    /// <param name="code"></param>
    /// <param name="handler"></param>
    public void RemoveHandler(HardWareEventType type, int code, HardWareEventHandler handler)
    {
        SortedList <int, List <HardWareEventHandler> > list = _hardWareEvents[(int)type];

        if (list.ContainsKey(code))
        {
            List <HardWareEventHandler> handlers = list[code];
            handlers.Remove(handler);
            if (handlers.Count == 0)
            {
                list.Remove(code);
            }
        }
    }