2025-11-27 16:36:46 +00:00
|
|
|
// Copyright (c) 2016-2025 AtomAI, All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// See the COPYRIGHT file at the top-level directory of this distribution and at
|
2017-05-25 14:25:28 +00:00
|
|
|
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
2025-06-08 17:51:14 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0>
|
|
|
|
|
//
|
|
|
|
|
// This file may not be copied, modified, or distributed
|
2017-05-25 14:25:28 +00:00
|
|
|
// 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() {
|
2022-03-21 17:05:02 +00:00
|
|
|
// typing "Hello World"
|
2025-11-28 14:55:54 +00:00
|
|
|
robotgo.Type("Hello World!", 0, 1)
|
2021-10-18 16:43:34 +00:00
|
|
|
robotgo.KeySleep = 100
|
2025-11-28 14:55:54 +00:00
|
|
|
robotgo.Type("だんしゃり")
|
2018-03-18 11:27:45 +00:00
|
|
|
|
2025-11-28 14:55:54 +00:00
|
|
|
robotgo.Type("Hi galaxy, hi stars, hi MT.Rainier, hi sea. こんにちは世界.")
|
|
|
|
|
robotgo.Type("So, hi, bye! 你好, 再见!")
|
2021-10-18 16:43:34 +00:00
|
|
|
robotgo.Sleep(1)
|
2022-02-04 08:02:34 +00:00
|
|
|
|
2025-11-28 14:55:54 +00:00
|
|
|
robotgo.Type("Hi, Seattle space needle, Golden gate bridge, One world trade center.")
|
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)
|
|
|
|
|
|
2025-11-28 14:55:54 +00:00
|
|
|
err := robotgo.Paste("paste string")
|
2022-02-04 08:02:34 +00:00
|
|
|
fmt.Println("PasteStr: ", err)
|
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")
|
2022-02-08 11:47:06 +00:00
|
|
|
robotgo.KeyTap(robotgo.Enter)
|
2021-10-18 16:43:34 +00:00
|
|
|
robotgo.KeySleep = 200
|
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")
|
2022-01-28 20:35:05 +00:00
|
|
|
if err != nil {
|
2019-05-17 14:43:33 +00:00
|
|
|
fmt.Println("robotgo.KeyTap run error is: ", err)
|
2018-12-29 15:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-01 07:12:24 +00:00
|
|
|
robotgo.KeyTap("h", "cmd")
|
2017-05-25 14:25:28 +00:00
|
|
|
|
2017-07-02 03:52:37 +00:00
|
|
|
// press "i", "alt", "command" Key combination
|
2022-02-08 11:47:06 +00:00
|
|
|
robotgo.KeyTap(robotgo.KeyI, robotgo.Alt, robotgo.Cmd)
|
2022-02-01 07:12:24 +00:00
|
|
|
robotgo.KeyTap("i", "alt", "cmd")
|
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)
|
2022-02-01 07:12:24 +00:00
|
|
|
robotgo.KeyTap("i", arr)
|
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
|
|
|
|
2022-04-14 15:57:09 +00:00
|
|
|
func special() {
|
2025-11-28 14:55:54 +00:00
|
|
|
robotgo.Type("{}")
|
2022-04-14 15:57:09 +00:00
|
|
|
robotgo.KeyTap("[", "]")
|
|
|
|
|
|
|
|
|
|
robotgo.KeyToggle("(")
|
|
|
|
|
robotgo.KeyToggle("(", "up")
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 16:09:37 +00:00
|
|
|
func keyToggle() {
|
2021-10-18 16:43:34 +00:00
|
|
|
// robotgo.KeySleep = 150
|
2022-02-08 11:47:06 +00:00
|
|
|
robotgo.KeyToggle(robotgo.KeyA)
|
2017-05-25 14:25:28 +00:00
|
|
|
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
|
|
|
|
2022-02-08 11:47:06 +00:00
|
|
|
err := robotgo.KeyToggle(robotgo.Enter)
|
2022-01-28 20:35:05 +00:00
|
|
|
if err != nil {
|
2019-05-17 14:43:33 +00:00
|
|
|
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() {
|
2021-08-27 16:51:57 +00:00
|
|
|
// robotgo.TypeStr("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
|
|
|
}
|
2021-03-05 18:58:53 +00:00
|
|
|
fmt.Println("text: ", 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()
|
2022-04-14 15:57:09 +00:00
|
|
|
special()
|
2018-10-07 16:09:37 +00:00
|
|
|
|
|
|
|
|
keyTap()
|
|
|
|
|
keyToggle()
|
|
|
|
|
|
|
|
|
|
cilp()
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 11:23:09 +00:00
|
|
|
func main() {
|
|
|
|
|
key()
|
|
|
|
|
}
|