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

Cannot detect Ctrl + V keypress in windows. #1301

Open
lazysegtree opened this issue Jan 31, 2025 · 0 comments
Open

Cannot detect Ctrl + V keypress in windows. #1301

lazysegtree opened this issue Jan 31, 2025 · 0 comments

Comments

@lazysegtree
Copy link

Describe the bug
Cannot detect Ctrl + V keypress in windows. On pressing Ctrl+V, I instead get the clipboard text's individual keys as input, one by one.

Setup
Please complete the following information along with version numbers, if applicable.

  • OS - Windows 11
  • Shell - Windows Powershell
  • Terminal Emulator - No emulator. Plain windows powershell
  • Terminal Multiplexer - None

To Reproduce
Steps to reproduce the behavior:

  1. Copy "hello" to windows clipboard
  2. Execute the source code provided below
  3. Press Ctrl + V
  4. Read the prog.log file for logs.

Source Code

Code

package main

import (
	"fmt"
	"log"
	"os"
	tea "github.com/charmbracelet/bubbletea"
)

type model struct {
	header string
	content string
	keycnt int
	// Add any fields you need for your model
}

func (m model) Init() tea.Cmd {
	return nil
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	m.keycnt++
	m.content = fmt.Sprintf("\n(Key %d)", m.keycnt)
	switch msg := msg.(type) {
	case tea.KeyMsg:
		m.content += fmt.Sprintf("msg = %v, typestr = %v, runes = %v, type = %d, paste=%v, alt=%v", 
			msg, msg.Type.String(), msg.Runes, msg.Type, msg.Paste, msg.Alt)

		log.Println(m.content)
		
		if msg.String() == "q" {
			return m, tea.Quit
		}
	}
	return m, nil
}

func (m model) View() string {
	return fmt.Sprintf("%s\n%s", m.header, m.content)
}

func main() {

	f,err := os.OpenFile("prog.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err!= nil {
		panic(err)
	}
	log.SetOutput(f)

	p := tea.NewProgram(model{header: "Press Enter or Ctrl + M\n"})
	if _,err:=p.Run(); err != nil {
		fmt.Printf("Error starting program: %v", err)
	}
}

Expected behavior
I should see Ctrl+V detected in logs.

Screenshots
Add screenshots to help explain your problem.
Logs

2025/01/31 10:55:51 
(Key 2)msg = , typestr = runes, runes = [0], type = -1, paste=false, alt=false
2025/01/31 10:55:51 
(Key 3)msg = h, typestr = runes, runes = [104], type = -1, paste=false, alt=false
2025/01/31 10:55:51 
(Key 4)msg = e, typestr = runes, runes = [101], type = -1, paste=false, alt=false
2025/01/31 10:55:51 
(Key 5)msg = l, typestr = runes, runes = [108], type = -1, paste=false, alt=false
2025/01/31 10:55:51 
(Key 6)msg = l, typestr = runes, runes = [108], type = -1, paste=false, alt=false
2025/01/31 10:55:51 
(Key 7)msg = o, typestr = runes, runes = [111], type = -1, paste=false, alt=false

Additional context
This related to yorukot/superfile#561 - We are trying to make Ctrl+V key work in our file manager on windows.

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

1 participant