示例#1
0
func main() {
	// you could script all this in bash
	// but where's the fun in that?
	// let's gostwrite it instead :-D

	kb, err := gostwriter.New("foo")
	guard(err)

	removeDemoFile(kb)
	wait(500)

	typeNano(kb)
	push(kb, key.CODE_ENTER)
	wait(500)

	typeText(kb)
	wait(500)
	exitNano(kb)
	wait(500)
	typeNanoDemoTxt(kb)
	push(kb, key.CODE_ENTER)
	wait(500)

	listAndCat(kb)

	err = kb.Destroy()
	guard(err)
}
示例#2
0
// Create new keyboard struct, delay between each keypress in ms.
func New(name string, delay time.Duration) (*KB, error) {
	kb, err := gostwriter.New(name)
	if err != nil {
		return nil, err
	}
	return &KB{
		Keyboard:           kb,
		Delay:              delay * time.Millisecond,
		isSpecialUppercase: regexp.MustCompile(`[!@#$%^&*()_+{}:"<>?~]+`),
	}, nil
}
示例#3
0
// uses the 't', 'e' and 's' keys to write 'test' to the
// console ten times. then it uses the 'ctrl' and 'c' keys
// to kill itself by emulating a 'CTRL+C' command
func main() {
	kb, err := gostwriter.New("foo")

	guard(err)

	t, err := kb.Get(key.CODE_T)
	guard(err)
	e, err := kb.Get(key.CODE_E)
	guard(err)
	s, err := kb.Get(key.CODE_S)
	guard(err)
	ret, err := kb.Get(key.CODE_ENTER)
	guard(err)

	ctrl, err := kb.Get(key.CODE_LEFTCTRL)
	guard(err)
	c, err := kb.Get(key.CODE_C)
	guard(err)

	log.Println("this demo will type the word 'test' and a newline 10 times")
	log.Println("then it will terminate itself by pressing CTRL + C")

	cnt := 0
	for {
		<-time.After(time.Millisecond * 100)
		push(t)
		<-time.After(time.Millisecond * 100)
		push(e)
		<-time.After(time.Millisecond * 100)
		push(s)
		<-time.After(time.Millisecond * 100)
		push(t)
		<-time.After(time.Millisecond * 500)
		push(ret)

		if cnt = cnt + 1; cnt == 10 {
			press(ctrl)
			press(c)
		}
	}

	kb.Destroy()
}