Skip to content

Numenorean/keypresses

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 

Repository files navigation

keypresses

This lib provides you checking if any key is pressed, fully built on win32api

Installation

Install this package with command go get -u github.com/Numenorean/keypresses

Finding virtualKeyCodes

Just go to this page https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes

Usage

Example of getting key state (even if current window is inactive)

package main

import (
	"github.com/Numenorean/keypresses"
	"time"
	"fmt"
)

func main() {
  for true {
    // 0x50 is virtualKeyCode, char "P" in human format
    fmt.Println(keypresses.IsKeyPressed(0x50))
    // Sleeping to prevent 100% CPU usage
    time.Sleep(1 * time.Microsecond)
  }
}

Example of getting key state only if current window is active

package main

import (
	"github.com/Numenorean/keypresses"
	"time"
	"fmt"
)

func main() {
  for true {
    // "false" argument means that to get key state, window should be active
    // "true" argument means that to get key state, window might not be active. The same as an IsKeyPressed function
    fmt.Println(keypresses.IsKeyPressedGlobal(0x50, false))
    // Sleeping to prevent 100% CPU usage
    time.Sleep(1 * time.Microsecond)
  }
}

About

This is a lib that provide you checking if any key is pressed

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages