getch

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

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

Go to latest
Published: Dec 23, 2018 License: BSD-3-Clause Imports: 7 Imported by: 6

README

GoDoc

go-getch

go-getch is a library to read the console-event (keyboard-hits or screen-resize), for the programming language Go for Windows,

Example

package main

import (
    "fmt"

    "github.com/zetamatta/go-getch"
)

const COUNT = 5

func main() {
    for i := 0; i < COUNT; i++ {
        fmt.Printf("[%d/%d] ", i+1, COUNT)
        e := getch.All()
        if k := e.Key; k != nil {
            fmt.Printf("\n%c %08X %08X %08X\n",
                k.Rune, k.Rune, k.Scan, k.Shift)
        } else if r := e.Resize; r != nil {
            fmt.Printf("\nWidth=%d Height=%d\n", r.Width, r.Height)
        } else {
            fmt.Println("\n(unknown event)")
        }
    }
}
  • go-getch supports the surrogate pair of Unicode.
  • go-getch is used in Windows CUI Shell NYAGOS

Types

type Event struct {
	Focus   *struct{}
	Key     *keyEvent // == KeyDown
	KeyDown *keyEvent
	KeyUp   *keyEvent
	Menu    *struct{}
	Mouse   *struct{}
	Resize  *resizeEvent
}

type keyEvent struct {
	Rune  rune
	Scan  uint16
	Shift uint32
}

type resizeEvent struct {
	Width  uint
	Height uint
}

Functions

func All() Event

Get all keyboard events.

func Rune() rune

Get a KeyDown event.

func Within(msec uintptr) (Event, error)

Get all keyboard events with time-out.

func RuneWithin(msec uintptr) (rune, error)

Get a KeyDown event with time-out.

Documentation

Index

Constants

View Source
const (
	RIGHT_ALT_PRESSED  = 1
	LEFT_ALT_PRESSED   = 2
	RIGHT_CTRL_PRESSED = 4
	LEFT_CTRL_PRESSED  = 8
	CTRL_PRESSED       = RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED
	ALT_PRESSED        = RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED
)
View Source
const (
	FROM_LEFT_1ST_BUTTON_PRESSED = 0x0001
	FROM_LEFT_2ND_BUTTON_PRESSED = 0x0004
	FROM_LEFT_3RD_BUTTON_PRESSED = 0x0008
	FROM_LEFT_4TH_BUTTON_PRESSED = 0x0010
	RIGHTMOST_BUTTON_PRESSED     = 0x0002
)
View Source
const ALL_EVENTS = consoleinput.ENABLE_WINDOW_INPUT // | consoleinput.ENABLE_MOUSE_INPUT
View Source
const IGNORE_RESIZE_EVENT uint32 = 0
View Source
const NUL = '\000'

Variables

View Source
var OnWindowResize func(w, h uint)

Deprecated: use All()

Functions

func Count

func Count() (int, error)

func DisableCtrlC

func DisableCtrlC()

func Flush

func Flush() error

func Full deprecated

func Full() (code rune, scan uint16, shift uint32)

Deprecated: use All() Get all keyboard-event.

func IsCtrlCPressed

func IsCtrlCPressed() bool

func Rune

func Rune() rune

Get character as a Rune

func RuneWithin

func RuneWithin(msec uintptr) (rune, error)

func Wait

func Wait(timeout_msec uintptr) (bool, error)

wait for keyboard event

Types

type Event

type Event struct {
	Focus   *struct{} // MS says it should be ignored
	Key     *keyEvent // == KeyDown
	KeyDown *keyEvent
	KeyUp   *keyEvent
	Menu    *struct{}                      // MS says it should be ignored
	Mouse   *consoleinput.MouseEventRecord // not supported,yet
	Resize  *resizeEvent
}

func All

func All() Event

Get all console-event (keyboard,resize,...)

func Within

func Within(msec uintptr) (Event, error)

func (Event) String

func (e Event) String() string

type Handle

type Handle struct {
	consoleinput.Handle
	// contains filtered or unexported fields
}

func New

func New() (*Handle, error)

func (*Handle) All

func (h *Handle) All() Event

Get all console-event (keyboard,resize,...)

func (*Handle) Close

func (h *Handle) Close()

func (*Handle) DisableCtrlC

func (h *Handle) DisableCtrlC()

func (*Handle) Flush

func (h *Handle) Flush() error

func (*Handle) IsCtrlCPressed

func (h *Handle) IsCtrlCPressed() bool

func (*Handle) Rune

func (h *Handle) Rune() rune

Get character as a Rune

func (*Handle) RuneWithin

func (h *Handle) RuneWithin(msec uintptr) (rune, error)

func (*Handle) Wait

func (h *Handle) Wait(timeout_msec uintptr) (bool, error)

wait for keyboard event

func (*Handle) Within

func (h *Handle) Within(msec uintptr) (Event, error)

Jump to

Keyboard shortcuts

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