1 Star 0 Fork 0

芝麻科技 / globalmousekeyhook

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

nuget master

Mouse and Keyboard Hooking Library in c#

NEWS!

Added support for detection of key combinations and sequences see.: Quickstart - Detecting Key Combinations and Seuqnces

What it does?

This library allows you to tap keyboard and mouse, to detect and record their activity even when an application is inactive and runs in background.

Prerequisites

  • Windows: .Net 4.0+

Installation and sources

  nuget install MouseKeyHook

Usage

private IKeyboardMouseEvents m_GlobalHook;

public void Subscribe()
{
    // Note: for the application hook, use the Hook.AppEvents() instead
    m_GlobalHook = Hook.GlobalEvents();

    m_GlobalHook.MouseDownExt += GlobalHookMouseDownExt;
    m_GlobalHook.KeyPress += GlobalHookKeyPress;
}

private void GlobalHookKeyPress(object sender, KeyPressEventArgs e)
{
    Console.WriteLine("KeyPress: \t{0}", e.KeyChar);
}

private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e)
{
    Console.WriteLine("MouseDown: \t{0}; \t System Timestamp: \t{1}", e.Button, e.Timestamp);

    // uncommenting the following line will suppress the middle mouse button click
    // if (e.Buttons == MouseButtons.Middle) { e.Handled = true; }
}

public void Unsubscribe()
{
    m_GlobalHook.MouseDownExt -= GlobalHookMouseDownExt;
    m_GlobalHook.KeyPress -= GlobalHookKeyPress;

    //It is recommened to dispose it
    m_GlobalHook.Dispose();
}

(also have a look at the Demo app included with the source)

How it works?

This library attaches to windows global hooks, tracks keyboard and mouse clicks and movement and raises common .NET events with KeyEventArgs and MouseEventArgs, so you can easily retrieve any information you need:

  • Mouse coordinates
  • Mouse buttons clicked
  • Mouse drag actions
  • Mouse wheel scrolls
  • Key presses and releases
  • Special key states

Additionally, there are MouseEventExtArgs and KeyEventExtArgs which provide further options:

  • Input suppression
  • Timestamp
  • IsMouseDown/Up
  • IsKeyDown/Up.

Troubleshooting and support

  • Usage or programming related question? Post it on StackOverflow using the tag mousekeyhook
  • Found a bug or missing a feature? Feed the issue tracker

Current project build status

The CI builds are generously hosted and run on the Travis and AppVeyor infrastructures.

Travis-CI AppVeyor
master master master
vNext vNext vNext

History

Year URL
2000 - 2008 http://www.codeproject.com/KB/cs/globalhook.aspx
2008 - 2015 https://globalmousekeyhook.codeplex.com/
2015 - now https://github.com/gmamaladze/globalmousekeyhook

Quick contributing guide

  • Fork and clone locally
  • Create a topic specific branch. Add some nice feature.
  • Send a Pull Request to spread the fun!

License

The MIT license (Refer to the LICENSE.md file)

Copyright (c) 2004-2015, George Mamaladze All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of asssdwd nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/sesametech-group/globalmousekeyhook.git
git@gitee.com:sesametech-group/globalmousekeyhook.git
sesametech-group
globalmousekeyhook
globalmousekeyhook
master

搜索帮助