-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #9
- Loading branch information
Showing
14 changed files
with
752 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022 The golang.design Initiative Authors. | ||
// All rights reserved. Use of this source code is governed | ||
// by a MIT license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/app" | ||
"fyne.io/fyne/v2/container" | ||
"fyne.io/fyne/v2/widget" | ||
"golang.design/x/hotkey" | ||
) | ||
|
||
func main() { | ||
w := app.New().NewWindow("golang.design/x/hotkey") | ||
label := widget.NewLabel("Hello golang.design!") | ||
button := widget.NewButton("Hi!", func() { label.SetText("Welcome :)") }) | ||
w.SetContent(container.NewVBox(label, button)) | ||
|
||
go func() { | ||
// Register a desired hotkey. | ||
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS) | ||
if err := hk.Register(); err != nil { | ||
panic("hotkey registration failed") | ||
} | ||
// Start listen hotkey event whenever it is ready. | ||
for range hk.Keydown() { | ||
button.Tapped(&fyne.PointEvent{}) | ||
} | ||
}() | ||
|
||
w.ShowAndRun() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2022 The golang.design Initiative Authors. | ||
// All rights reserved. Use of this source code is governed | ||
// by a MIT license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"gioui.org/app" | ||
"gioui.org/unit" | ||
"golang.design/x/hotkey" | ||
) | ||
|
||
func main() { | ||
go fn() | ||
app.Main() | ||
} | ||
|
||
func fn() { | ||
w := app.NewWindow(app.Title("golang.design/x/hotkey"), app.Size(unit.Dp(200), unit.Dp(200))) | ||
|
||
go reghk() | ||
|
||
for range w.Events() { | ||
} | ||
} | ||
|
||
func reghk() { | ||
// Register a desired hotkey. | ||
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS) | ||
if err := hk.Register(); err != nil { | ||
panic("hotkey registration failed") | ||
} | ||
|
||
// Unregister the hotkey when keydown event is triggered | ||
for range hk.Keydown() { | ||
hk.Unregister() | ||
} | ||
|
||
// Exist the app. | ||
os.Exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 The golang.design Initiative Authors. | ||
// All rights reserved. Use of this source code is governed | ||
// by a MIT license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/go-gl/glfw/v3.3/glfw" | ||
"golang.design/x/hotkey" | ||
) | ||
|
||
func init() { | ||
runtime.LockOSThread() | ||
} | ||
|
||
func main() { | ||
err := glfw.Init() | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer glfw.Terminate() | ||
window, err := glfw.CreateWindow(640, 480, "golang.design/x/hotkey", nil, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
go func() { | ||
// Register a desired hotkey. | ||
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS) | ||
if err := hk.Register(); err != nil { | ||
panic("hotkey registration failed") | ||
} | ||
// Start listen hotkey event whenever it is ready. | ||
for range hk.Keydown() { | ||
fmt.Println("keydown!") | ||
} | ||
}() | ||
|
||
window.MakeContextCurrent() | ||
for !window.ShouldClose() { | ||
window.SwapBuffers() | ||
glfw.PollEvents() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.