Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue using GetSingleKey #34

Open
PG-0126 opened this issue Feb 11, 2023 · 5 comments
Open

issue using GetSingleKey #34

PG-0126 opened this issue Feb 11, 2023 · 5 comments

Comments

@PG-0126
Copy link

PG-0126 commented Feb 11, 2023

GetSingleKey is not working properly in this new version.
It is not returning instantly.
Let me explain the whole scenario.....

suppose i press 'a'...
it will not detect nor display any result.

then suppose i press 'e' (or any random alphabet or key)
this time it displays the value of the previous action (i.e. value of 'a')

i hope u got it...

please fix this issue
following version works fine
github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807

but latest one is having issue

@AuThomasPrime
Copy link

I am experiencing the same problem. Key presses with GetSingleKey return a ch rune with values from the previous key press. The older version suggested by @PG-0126 works as expected.

@mn519019
Copy link

mn519019 commented May 7, 2023

Same here. I am experiencing a same issue. So there is a gap for the first input when it takes the "GetStringKey". Therefore, the first keystroke is being ignored.

@kevgo
Copy link

kevgo commented Jan 11, 2024

I am able to reproduce this problem on Windows, in the Git Bash shell and in VSCode's terminal. Works correctly on Linux, macOS, Windows CMD, and Windows Powershell.

@kevgo
Copy link

kevgo commented Jan 11, 2024

The last working version seems "Pass alt combinations through as Key+Rune (#23)". You can use it like this:

require (
	github.com/eiannone/keyboard v0.0.0-20220607221743-a9f4cc43507a
)

This bug gets introduced in one of these two commits:

  • "Removed syscall use where possible, tidied up some logic (#25)"
    I can't test this commit, it leads to a crash on Windows
  • "Fix SyscallN call and multiple cleanups. (#26)"

@brawll
Copy link

brawll commented Dec 29, 2024

I am able to reproduce this problem on Windows, in the Git Bash shell and in VSCode's terminal. Works correctly on Linux, macOS, Windows CMD, and Windows Powershell.

version - github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 (latest as of now)
I am getting this issue in WIndows Powershell & Windows CMD. An example

package main

import (
	"fmt"
	"log"

	"github.com/eiannone/keyboard"
)

func main() {
	err := keyboard.Open()
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		_ = keyboard.Close()
	}()

	fmt.Println("Press any key on the keyboard. Press ESC to quit.")

	for {
		char, key, err := keyboard.GetSingleKey()
		if err != nil {
			log.Fatal(err)
		}

		if key != 0 {
			fmt.Println("you pressed", char, key)
		} else {
			fmt.Println("You pressed", char)
		}

		if key == keyboard.KeyEsc {
			break
		}
	}

	fmt.Println("Program exiting...")
}

Although it is not an issue in the version mentioned in your comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants