-
-
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 #17
- Loading branch information
Showing
3 changed files
with
90 additions
and
54 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 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 |
---|---|---|
@@ -1,28 +1,29 @@ | ||
// 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" | ||
"log" | ||
|
||
"golang.design/x/hotkey" | ||
"golang.design/x/hotkey/mainthread" | ||
) | ||
|
||
func main() { mainthread.Init(fn) } | ||
func main() { mainthread.Init(fn) } // Not necessary when use in Fyne, Ebiten or Gio. | ||
func fn() { | ||
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS) | ||
err := hk.Register() | ||
if err != nil { | ||
log.Fatalf("hotkey: failed to register hotkey: %v", err) | ||
return | ||
} | ||
fmt.Printf("hotkey: %v is registered\n", hk) | ||
|
||
log.Printf("hotkey: %v is registered\n", hk) | ||
<-hk.Keydown() | ||
fmt.Printf("hotkey: %v is down\n", hk) | ||
log.Printf("hotkey: %v is down\n", hk) | ||
<-hk.Keyup() | ||
fmt.Printf("hotkey: %v is up\n", hk) | ||
log.Printf("hotkey: %v is up\n", hk) | ||
hk.Unregister() | ||
fmt.Printf("hotkey: %v is unregistered\n", hk) | ||
log.Printf("hotkey: %v is unregistered\n", hk) | ||
} |
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