Skip to content

Commit

Permalink
update: move to cross platform hotkey module
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijit-hota committed Apr 25, 2022
1 parent d5db304 commit 84e209a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 55 deletions.
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module bingo

go 1.18

require github.com/MarinX/keylogger v0.0.0-20210528193429-a54d7834cc1a

require github.com/atotto/clipboard v0.1.4

require (
golang.design/x/hotkey v0.3.0
golang.design/x/mainthread v0.3.0 // indirect
)
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
github.com/MarinX/keylogger v0.0.0-20210528193429-a54d7834cc1a h1:ItKXWegGGThcahUf+ylKFa5pwqkRJofaOyeGdzwO2mM=
github.com/MarinX/keylogger v0.0.0-20210528193429-a54d7834cc1a/go.mod h1:aKzZ7D15UvH5LboXkeLmcNi+s/f805vUfB+BfW1fqd4=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
golang.design/x/hotkey v0.3.0 h1:rz/MLaZOEfvDQidizmxgIVzF1US74SdvOXW+1KBjOQ4=
golang.design/x/hotkey v0.3.0/go.mod h1:M8SGcwFYHnKRa83FpTFQoZvPO5vVT+kWPztFqTQKmXA=
golang.design/x/mainthread v0.3.0 h1:UwFus0lcPodNpMOGoQMe87jSFwbSsEY//CA7yVmu4j8=
golang.design/x/mainthread v0.3.0/go.mod h1:vYX7cF2b3pTJMGM/hc13NmN6kblKnf4/IyvHeu259L0=
golang.org/x/sys v0.0.0-20201022201747-fb209a7c41cd h1:WgqgiQvkiZWz7XLhphjt2GI2GcGCTIZs9jqXMWmH+oc=
golang.org/x/sys v0.0.0-20201022201747-fb209a7c41cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
65 changes: 14 additions & 51 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"log"
"net/http"
"strings"

KL "github.com/MarinX/keylogger"
CB "github.com/atotto/clipboard"
"github.com/atotto/clipboard"
"golang.design/x/hotkey"
"golang.design/x/hotkey/mainthread"
)

func dataserver() {
Expand All @@ -21,60 +21,23 @@ func dataserver() {
log.Fatal(err)
}

func getKeylogger() *KL.KeyLogger {
// Find keyboard
keyboard := KL.FindKeyboardDevice()
if len(keyboard) <= 0 {
log.Fatal("No keyboard found. You will need to provide manual input path.")
} else {
log.Println(keyboard)
}

// Create a keylogger
keylogger, err := KL.New(keyboard)
func fn() {
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.Key(0x2f))
err := hk.Register()
if err != nil {
log.Fatal(err)
return
}

if err != nil {
log.Fatal(err)
for range hk.Keydown() {
text, err := clipboard.ReadAll()
if err != nil {
panic(err)
}
fmt.Println(text)
}
return keylogger
}

func main() {

go dataserver()

keylogger := getKeylogger()
defer keylogger.Close()

shortcuts := map[string]bool{"CTRL": false, "SHIFT": false, "/": false}

in := keylogger.Read()
for i := range in {
// Listen to only key press & release events
if i.Type == KL.EvKey && (i.KeyPress() || i.KeyRelease()) {
gen := strings.Split(i.KeyString(), "_")
key := gen[len(gen)-1]

if _, ok := shortcuts[key]; ok {
shortcuts[key] = i.KeyPress()
}

allPressed := true
for _, v := range shortcuts {
allPressed = (allPressed && v)
}
if allPressed {
str, err := CB.ReadAll()
if err != nil {
panic(err)
}

fmt.Println("Shortcut!")
fmt.Println(str)
}
}
}
mainthread.Init(fn)
}

0 comments on commit 84e209a

Please sign in to comment.