gohotkey

package module
v0.0.0-...-31ae211 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

README

GoHotKey

A simple package to capture the keyboard in Windows. (tested on Windows 10, 64-bit)

Download

go get github.com/Adrosar/gohotkey

How to use

package main

import (
	"fmt"
	"log"

	"github.com/Adrosar/gohotkey"
)

type handler struct{}

func (h *handler) Do(k gohotkey.Hotkey) {
	fmt.Println(k.String())
}

func main() {
	k := gohotkey.NewKeyboard()
	k.SetHandler(&handler{})

	k.Add(true, true, false, false, 'K')    // ALT + CTRL + K
	k.Add(false, false, false, true, 'N')   // Win + N
	k.Add(false, false, false, false, 0xB3) // Additional "play/pause" button

	err := k.Listen()
	if err != nil {
		log.Fatalln(err)
	}
}

basic example

How to build

Go to the directory where the main.go file is located and execute the command:

go build -o app.exe main.go

Early stage

The software was created for personal use and is in the early stages of development.

License

I put the software temporarily under the Go-compatible BSD license. If this prevents someone from using the software, do let me know and I'll consider changing it.

Author

Adrian Gargula | github.com/Adrosar | bitbucket.org/Adrosar

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Do(k Hotkey)
}

type Hotkey

type Hotkey struct {
	Id      uint
	IsAlt   bool
	IsCtrl  bool
	IsShift bool
	IsWin   bool
	Rune    rune
}

func (*Hotkey) Char

func (k *Hotkey) Char() string

func (*Hotkey) Code

func (k *Hotkey) Code() int32

func (*Hotkey) String

func (k *Hotkey) String() string

type Keyboard

type Keyboard struct {
	// contains filtered or unexported fields
}

func NewKeyboard

func NewKeyboard() *Keyboard

func (*Keyboard) Add

func (kb *Keyboard) Add(isAlt bool, isCtrl bool, isShift bool, isWin bool, char rune) uint

Adds a key combination.

Argument "char" see https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes

func (*Keyboard) Listen

func (kb *Keyboard) Listen() error

func (*Keyboard) SetDelay

func (kb *Keyboard) SetDelay(t time.Duration)

func (*Keyboard) SetHandler

func (kb *Keyboard) SetHandler(h Handler)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL