~eliasnaur/gio-patches

app/internal/window: allow punctuation as keycode events v4 PROPOSED

Larry Clapp: 1
 app/internal/window: allow punctuation as keycode events

 2 files changed, 8 insertions(+), 6 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/9100/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH v4] app/internal/window: allow punctuation as keycode events Export this patch

Allows things like "ctrl-{" and ".".

All punctuation is returned as-is, e.g. "!" is "!", not "shift-1", 
and "{" is "{", not "shift-[".

Also add the Enter key as a known key (fn-return on my Mac).

Signed-off-by: Larry Clapp <larry@theclapp.org>
---
 app/internal/window/os_macos.go |  4 +++-
 io/key/key.go                   | 10 +++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)

Commentary: this is against rebased current master.

diff --git a/app/internal/window/os_macos.go b/app/internal/window/os_macos.go
index dc8ab55..cb3ef10 100644
--- a/app/internal/window/os_macos.go
+++ b/app/internal/window/os_macos.go
@@ -292,7 +292,7 @@ func Main() {
}

func convertKey(k rune) (string, bool) {
	if '0' <= k && k <= '9' || 'A' <= k && k <= 'Z' {
	if '!' <= k && k <= '`' || '{' <= k && k <= '~' {
		return string(k), true
	}
	if 'a' <= k && k <= 'z' {
@@ -312,6 +312,8 @@ func convertKey(k rune) (string, bool) {
		n = key.NameDownArrow
	case 0xd:
		n = key.NameReturn
	case 0x3:
		n = key.NameEnter
	case C.NSHomeFunctionKey:
		n = key.NameHome
	case C.NSEndFunctionKey:
diff --git a/io/key/key.go b/io/key/key.go
index e90c5df..92b3eea 100644
--- a/io/key/key.go
+++ b/io/key/key.go
@@ -39,12 +39,12 @@ type FocusEvent struct {
// An Event is generated when a key is pressed. For text input
// use EditEvent.
type Event struct {
	// Name of the key. For letters, the upper case form is used.
	// Use the Name* constants for special keys suchs as the arrow
	// keys.
	// Name of the key. For letters, the upper case form is used. The shift
	// modifier is taken into account, all other modifiers are ignored. For
	// example, the "shift-1" combination gives the Name "!" with the US
	// keyboard layout.
	Name string
	// Modifiers is the set of active modifiers when
	// the key was pressed.
	// Modifiers is the set of active modifiers when the key was pressed.
	Modifiers Modifiers
}

-- 
2.23.0