Beispiel #1
0
// http://blog.sina.com.cn/s/blog_648d306d0101gjxh.html
func emuInputText(c string, shift bool) {
	scanKey := *syscall.StringToUTF16Ptr(c)
	var input win.KEYBD_INPUT
	if shift {
		input.Type = win.INPUT_KEYBOARD
		input.Ki.WVk = win.VK_SHIFT
		win.SendInput(1, unsafe.Pointer(&input), int32(unsafe.Sizeof(input)))
	}

	input.Type = win.INPUT_KEYBOARD
	input.Ki.WVk = scanKey
	win.SendInput(1, unsafe.Pointer(&input), int32(unsafe.Sizeof(input)))

	input.Type = win.INPUT_KEYBOARD
	input.Ki.WVk = scanKey
	input.Ki.DwFlags = win.KEYEVENTF_KEYUP
	win.SendInput(1, unsafe.Pointer(&input), int32(unsafe.Sizeof(input)))

	if shift {
		input.Type = win.INPUT_KEYBOARD
		input.Ki.WVk = win.VK_SHIFT
		input.Ki.DwFlags = win.KEYEVENTF_KEYUP
		win.SendInput(1, unsafe.Pointer(&input), int32(unsafe.Sizeof(input)))
	}

	win.SendInput(1, unsafe.Pointer(&input), int32(unsafe.Sizeof(input)))
}
Beispiel #2
0
func send_key_event(keyCode uint16, isKeyUp bool) {
	var input win.KEYBD_INPUT
	input.Type = win.INPUT_KEYBOARD
	input.Ki.WVk = keyCode
	if isKeyUp {
		input.Ki.DwFlags = win.KEYEVENTF_KEYUP
	}
	win.SendInput(1, unsafe.Pointer(&input), int32(unsafe.Sizeof(input)))
	time.Sleep(3 * time.Millisecond)
}