Skip to content

Cannot detect Ctrl + Space keypress in Windows #1495

@schollz

Description

@schollz

Describe the bug
Cannot detect Ctrl + Space keypress in Windows, instead it looks identical to pressing "Space".

Setup

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

To Reproduce
Steps to reproduce the behavior:

  1. Execute the source code below
  2. Press Ctrl + Space
  3. 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+space, or something different than just "space"

Screenshots

Space produces:
Image

Ctrl+Space produces the same:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions