robotgo/examples/key/main.go

121 lines
2.6 KiB
Go
Raw Permalink Normal View History

2018-02-01 16:07:44 +00:00
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
2017-05-25 14:25:28 +00:00
// file at the top-level directory of this distribution and at
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
package main
import (
2017-06-11 11:07:58 +00:00
"fmt"
2017-05-25 14:25:28 +00:00
"github.com/go-vgo/robotgo"
// "go-vgo/robotgo"
)
2018-10-07 16:09:37 +00:00
func typeStr() {
2017-07-02 03:52:37 +00:00
// importing "Hello World"
2019-12-16 13:35:55 +00:00
robotgo.TypeStr("Hello World!", 1.0)
2017-07-02 03:52:37 +00:00
2019-07-11 15:43:13 +00:00
robotgo.TypeStr("だんしゃり")
2018-12-12 20:59:14 +00:00
robotgo.MicroSleep(10.2)
2018-03-18 11:27:45 +00:00
2019-07-11 15:43:13 +00:00
robotgo.TypeStr("Hi galaxy. こんにちは世界.")
2018-12-12 20:59:14 +00:00
robotgo.Sleep(2)
2019-12-16 13:35:55 +00:00
// robotgo.TypeString("So, hi, bye!")
2018-12-12 20:59:14 +00:00
robotgo.MilliSleep(100)
2018-03-18 11:27:45 +00:00
2019-07-11 15:43:13 +00:00
ustr := uint32(robotgo.CharCodeAt("So, hi, bye!", 0))
2018-01-18 13:39:27 +00:00
robotgo.UnicodeType(ustr)
2019-07-11 15:43:13 +00:00
robotgo.PasteStr("paste string")
2018-10-07 16:09:37 +00:00
}
2018-01-18 13:39:27 +00:00
2018-10-07 16:09:37 +00:00
func keyTap() {
2017-07-02 03:52:37 +00:00
// press "enter"
robotgo.KeyTap("enter")
2018-12-12 20:59:14 +00:00
robotgo.KeyTap("a")
2019-10-25 17:03:24 +00:00
robotgo.MilliSleep(100)
2019-01-06 16:29:16 +00:00
robotgo.KeyTap("a", "ctrl")
2018-12-11 14:53:03 +00:00
2017-07-02 03:52:37 +00:00
// hide window
2019-01-06 16:29:16 +00:00
err := robotgo.KeyTap("h", "cmd")
2019-05-17 14:43:33 +00:00
if err != "" {
fmt.Println("robotgo.KeyTap run error is: ", err)
2018-12-29 15:42:56 +00:00
}
2019-01-06 16:29:16 +00:00
robotgo.KeyTap("h", "cmd", 12)
2017-05-25 14:25:28 +00:00
2017-07-02 03:52:37 +00:00
// press "i", "alt", "command" Key combination
2017-05-25 14:25:28 +00:00
robotgo.KeyTap("i", "alt", "command")
2019-03-30 16:18:29 +00:00
robotgo.KeyTap("i", "alt", "cmd", 11)
2018-12-11 14:53:03 +00:00
2019-01-06 16:29:16 +00:00
arr := []string{"alt", "cmd"}
2017-05-25 14:25:28 +00:00
robotgo.KeyTap("i", arr)
2017-12-24 15:01:22 +00:00
robotgo.KeyTap("i", arr, 12)
2017-05-25 14:25:28 +00:00
2019-03-30 16:18:29 +00:00
robotgo.KeyTap("i", "cmd", " alt", "shift")
2017-07-02 03:52:37 +00:00
// close window
2019-01-06 16:29:16 +00:00
robotgo.KeyTap("w", "cmd")
2018-12-11 14:53:03 +00:00
2017-07-02 03:52:37 +00:00
// minimize window
2019-01-06 16:29:16 +00:00
robotgo.KeyTap("m", "cmd")
robotgo.KeyTap("f1", "ctrl")
2017-05-25 14:25:28 +00:00
robotgo.KeyTap("a", "control")
2018-10-07 16:09:37 +00:00
}
2017-05-25 14:25:28 +00:00
2018-10-07 16:09:37 +00:00
func keyToggle() {
2017-05-25 14:25:28 +00:00
robotgo.KeyToggle("a", "down")
robotgo.KeyToggle("a", "down", "alt")
2019-10-25 17:03:24 +00:00
robotgo.Sleep(1)
2020-03-11 18:29:07 +00:00
2019-03-30 16:18:29 +00:00
robotgo.KeyToggle("a", "up", "alt", "cmd")
2019-10-25 17:03:24 +00:00
robotgo.MilliSleep(100)
2019-03-30 16:18:29 +00:00
robotgo.KeyToggle("q", "up", "alt", "cmd", "shift")
2018-12-29 15:42:56 +00:00
err := robotgo.KeyToggle("enter", "down")
2019-05-17 14:43:33 +00:00
if err != "" {
fmt.Println("robotgo.KeyToggle run error is: ", err)
2018-12-29 15:42:56 +00:00
}
2018-10-07 16:09:37 +00:00
}
2017-05-25 14:25:28 +00:00
2018-10-07 16:09:37 +00:00
func cilp() {
2019-12-16 13:35:55 +00:00
// robotgo.TypeString("en")
2017-06-11 11:07:58 +00:00
2017-07-02 03:52:37 +00:00
// write string to clipboard
2020-03-11 18:29:07 +00:00
e := robotgo.WriteAll("テストする")
if e != nil {
fmt.Println("robotgo.WriteAll err is: ", e)
}
2017-07-02 03:52:37 +00:00
// read string from clipboard
2017-06-11 11:07:58 +00:00
text, err := robotgo.ReadAll()
2019-05-17 14:43:33 +00:00
if err != nil {
fmt.Println("robotgo.ReadAll err is: ", err)
2017-06-11 11:07:58 +00:00
}
2019-05-17 14:43:33 +00:00
fmt.Println(text)
2017-05-25 14:25:28 +00:00
}
2018-07-13 11:23:09 +00:00
2018-10-07 16:09:37 +00:00
func key() {
////////////////////////////////////////////////////////////////////////////////
// Control the keyboard
////////////////////////////////////////////////////////////////////////////////
typeStr()
keyTap()
keyToggle()
cilp()
}
2018-07-13 11:23:09 +00:00
func main() {
key()
}