Skip to content

Commit

Permalink
kill channels properly
Browse files Browse the repository at this point in the history
  • Loading branch information
lyubchev committed Sep 11, 2020
1 parent 9e9cfc2 commit ab0d2fc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ func main() {

if ev.Message == types.WM_KEYUP && ev.VKCode == types.VK_4 {
qc <- struct{}{}
close(kbC)

err := keyboard.Uninstall()
if err != nil {
panic(err)
}
}
}

err = keyboard.Uninstall()
if err != nil {
panic(err)
}
}

func MoveClick(x, y int, delay time.Duration) {
Expand Down Expand Up @@ -148,6 +147,8 @@ func RegKbHook() (chan types.KeyboardEvent, error) {
}

func Play(kbC chan types.KeyboardEvent, qc chan struct{}, levelsToPass, x0, y0, x1, y1 int) {
defer close(kbC)

bounds := image.Rect(x0, y0, x1, y1)
img, err := screenshot.CaptureRect(bounds)
if err != nil {
Expand Down Expand Up @@ -201,10 +202,8 @@ func Play(kbC chan types.KeyboardEvent, qc chan struct{}, levelsToPass, x0, y0,

select {
case <-termC:
close(kbC)
return
case <-qc:
close(kbC)
return
default:
for y := screenshotBounds.Min.Y; y < height; y += 10 {
Expand Down

0 comments on commit ab0d2fc

Please sign in to comment.