How to use setTouchCoords method in fMBT

Best Python code snippet using fMBT_python

fmbtwindows_agent.py

Source:fmbtwindows_agent.py Github

copy

Full Screen

...443ctypes.windll.user32.VkKeyScanW.argtypes = [ctypes.c_wchar]444ctypes.windll.user32.VkKeyScanW.restype = ctypes.c_short445if not "touchInfoLock" in globals():446 touchInfoLock = thread.allocate_lock()447def setTouchCoords(touchInfo, x, y, fingerRadius=5, finger=0):448 if finger == 0:449 ti = touchInfo450 elif finger == 1:451 ti = touchInfo2452 else:453 raise ValueError("invalid finger number: %s, expected 0 or 1" % (finger,))454 ti.pointerInfo.ptPixelLocation.x = x455 ti.pointerInfo.ptPixelLocation.y = y456 ti.rcContact.left = x - fingerRadius457 ti.rcContact.right = x + fingerRadius458 ti.rcContact.top = y - fingerRadius459 ti.rcContact.bottom = y + fingerRadius460def _sendTouch(pointerFlags, errorWhen="doTouch", fingers=1):461 if fingers == 1:462 touchInfo.pointerInfo.pointerFlags = pointerFlags463 try:464 success = ctypes.windll.user32.InjectTouchInput(1, ctypes.byref(touchInfo))465 except AttributeError:466 raise NotImplementedError("this windows version does not support touch injection")467 elif fingers == 2:468 touchInfo.pointerInfo.pointerFlags = pointerFlags469 touchInfo2.pointerInfo.pointerFlags = pointerFlags470 try:471 success = ctypes.windll.user32.InjectTouchInput(2, ctypes.byref(touchInfoArray))472 except AttributeError:473 raise NotImplementedError("this windows version does not support touch injection")474 else:475 success = 1476 if (success == 0):477 return False478 else:479 return True480def _touchHold():481 # Keep updating previous touchDown or touchMove coordinates482 # to avoid InjectTouchInput timeout483 _touchUpdateInterval = 0.25 # seconds484 while True:485 time.sleep(_touchUpdateInterval)486 touchInfoLock.acquire()487 try:488 if not (touchInfo.pointerInfo.pointerFlags & POINTER_FLAG_INCONTACT):489 break490 if not _sendTouch(POINTER_FLAG_UPDATE |491 POINTER_FLAG_INRANGE |492 POINTER_FLAG_INCONTACT, "_touchHold"):493 break494 finally:495 touchInfoLock.release()496def touchDown(x, y, fingerRadius=5, holdEvents=True, finger=0, sendFingers=1):497 touchInfoLock.acquire()498 try:499 setTouchCoords(touchInfo, x, y, fingerRadius, finger)500 ok = _sendTouch(POINTER_FLAG_DOWN |501 POINTER_FLAG_INRANGE |502 POINTER_FLAG_INCONTACT, "touchDown",503 sendFingers)504 if ok and holdEvents:505 thread.start_new_thread(_touchHold, ()) # update until raised506 return ok507 finally:508 touchInfoLock.release()509def touchMove(x, y, fingerRadius=5, finger=0, sendFingers=1):510 touchInfoLock.acquire()511 try:512 setTouchCoords(touchInfo, x, y, fingerRadius, finger)513 return _sendTouch(POINTER_FLAG_UPDATE |514 POINTER_FLAG_INRANGE |515 POINTER_FLAG_INCONTACT, "touchMove",516 sendFingers)517 finally:518 touchInfoLock.release()519def touchUp(x, y, fingerRadius=5, finger=0, sendFingers=1):520 touchInfoLock.acquire()521 try:522 setTouchCoords(touchInfo, x, y, fingerRadius, finger)523 moveOk = _sendTouch(POINTER_FLAG_UPDATE |524 POINTER_FLAG_INRANGE |525 POINTER_FLAG_INCONTACT,526 "touchUp move to final location",527 sendFingers)528 return _sendTouch(POINTER_FLAG_UP, "touchUp", sendFingers) and moveOk529 finally:530 touchInfoLock.release()531def touchPinch(finger0startXY, finger0endXY,532 finger1startXY, finger1endXY,533 count=10, duration=0.75):534 f0x, f0y = finger0startXY535 f1x, f1y = finger1startXY536 f0dx = float(finger0endXY[0] - finger0startXY[0]) / count...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful