Code Monkey home page Code Monkey logo

inputhook's Introduction

inputhook

A Go library for Windows that is used for hooking low-level user input. Could be used to log the keyboard and mouse event, or to do other things you want.

Usage

First, you will need to define a callback function. For a keyboard event callback, the definition of function is like:

type KeyboardHookCallback func(keyEvent int, keyCode int)

An example of it:

func hookCallback(keyEvent int, keyCode int) {
	fmt.Println("keyEvent:", keyEvent)
	fmt.Println("keyCode:", keyCode)
}

Then in the main function, or the place you want to start listening to the input event, write the code like this:

inputhook.HookKeyboard(hookCallback)

This will make the keyboard hook start working. For a very simple completed demo, see as followed:

package main

import (
	"fmt"
	"github.com/vence722/inputhook"
)

func hookCallback(keyEvent int, keyCode int) {
	fmt.Println("keyEvent:", keyEvent)
	fmt.Println("keyCode:", keyCode)
}

func main() {
	inputhook.HookKeyboard(hookCallback)
	ch := make(chan bool)
	<-ch
}

For the mouse event hooking, it's very similar to the keyboard hook. One of the differences is it requires user to implement another callback function:

type MouseHookCallback func(x int64, y int64, event int, data uint64)

Then you should call HookMouse() to make the hooking work:

inputhook.HookMoused(hookCallback)

Have Fun!

inputhook's People

Contributors

vence722 avatar

Stargazers

 avatar qomos avatar Lany avatar Will avatar Rohan Likhite avatar  avatar Liu Xinyun avatar

Watchers

 avatar

inputhook's Issues

Build Error

How would one do a cross build supposing not using windows , i get error

undefined: inputhook.HookKeyboard

example usage

Hi nice package kudos , an example of usage would be most appropriate , don't you agree ?

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.