예제 #1
0
파일: callbacks.go 프로젝트: CodyGuo/gapp
// 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)))
}
예제 #2
0
파일: sendinput.go 프로젝트: CodyGuo/gapp
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)
}
예제 #3
0
파일: sendinput.go 프로젝트: CodyGuo/gapp
// unicode char key press
func UniKeyPress(keyCode uint16) {
	var input = [2]win.KEYBD_INPUT{}

	input[0].Type = win.INPUT_KEYBOARD
	input[0].Ki.WVk = 0
	input[0].Ki.WScan = keyCode
	input[0].Ki.DwFlags = win.KEYEVENTF_UNICODE

	input[1].Type = win.INPUT_KEYBOARD
	input[1].Ki.WVk = 0
	input[1].Ki.WScan = keyCode
	input[1].Ki.DwFlags = win.KEYEVENTF_UNICODE | win.KEYEVENTF_KEYUP

	win.SendInput(2, unsafe.Pointer(&input[0]), int32(unsafe.Sizeof(input[0])))
	time.Sleep(5 * time.Millisecond)
}
예제 #4
0
파일: callbacks.go 프로젝트: CodyGuo/gapp
// 模拟点击
func win_emuClick(browser *cef.Browser, message *cef.CefProcessMessage) interface{} {
	fmt.Printf("win_emuClick\n")
	handle := browser.GetWindowHandle()
	openerHandle := browser.GetOpenerWindowHandle()
	rootHandle := browser.GetRootWindowHandle()
	fmt.Printf("win_start_browser handle=%v openerHandle=%v rootHandle=%v\n", handle, openerHandle, rootHandle)
	//win.ShowWindow(win.HWND(rootHandle), win.SW_MAXIMIZE)
	// 模拟点击
	// 查找窗口
	url := message.GetArgumentList().GetString(1)
	fmt.Printf("url=%v\n", url)
	w, ok := windowHolders[url]
	if ok {
		fmt.Printf("找到窗口\n")
		b, o := cef.BrowserByHandle(unsafe.Pointer(w))
		if o {
			x := message.GetArgumentList().GetInt(2)
			y := message.GetArgumentList().GetInt(3)
			buttonType := message.GetArgumentList().GetBool(4)
			fmt.Printf("X=%v Y=%v ButtonType=%v\n", x, y, buttonType)
			rootHandle = b.GetRootWindowHandle()
			//win.ShowWindow(win.HWND(rootHandle), win.SW_MAXIMIZE)
			// 模拟鼠标
			var pt win.POINT
			pt.X = int32(x) // This is your click coordinates
			pt.Y = int32(y)

			hWnd := win.HWND(rootHandle)

			go func() {
				win.SetForegroundWindow(hWnd)
				time.Sleep(3 * time.Second)

				win.ClientToScreen(hWnd, &pt)

				fmt.Printf("ClientToScreen X=%v Y=%v\n", pt.X, pt.Y)

				cx_screen := win.GetSystemMetrics(win.SM_CXSCREEN) //屏幕 宽
				cy_screen := win.GetSystemMetrics(win.SM_CYSCREEN) //     高

				real_x := 65535 * pt.X / cx_screen //转换后的 x
				real_y := 65535 * pt.Y / cy_screen //         y

				var input win.MOUSE_INPUT
				input.Type = win.INPUT_MOUSE
				input.Mi.Dx = real_x
				input.Mi.Dy = real_y
				if buttonType {
					input.Mi.DwFlags = (win.MOUSEEVENTF_ABSOLUTE | win.MOUSEEVENTF_MOVE | win.MOUSEEVENTF_RIGHTDOWN | win.MOUSEEVENTF_RIGHTUP)
				} else {
					input.Mi.DwFlags = (win.MOUSEEVENTF_ABSOLUTE | win.MOUSEEVENTF_MOVE | win.MOUSEEVENTF_LEFTDOWN | win.MOUSEEVENTF_LEFTUP)
				}
				input.Mi.MouseData = 0
				input.Mi.DwExtraInfo = 0
				input.Mi.Time = 0
				win.SendInput(2, unsafe.Pointer(&input), int32(unsafe.Sizeof(input)))

				fmt.Printf("点击")
			}()
			//hWnd = win.WindowFromPoint(pt)
		}
	} else {
		fmt.Printf("找不到窗口\n")
	}
	return 0
}