How to use _keyToScancode method in fMBT

Best Python code snippet using fMBT_python

fmbtrdp.py

Source:fmbtrdp.py Github

copy

Full Screen

...632 ',': ("VK_OEM_COMMA", []), '<': ("VK_OEM_COMMA", ["VK_LSHIFT"]),633 '.': ("VK_OEM_PERIOD", []), '>': ("VK_OEM_PERIOD", ["VK_LSHIFT"]),634 '/': ("VK_OEM_2", []), '?': ("VK_OEM_2", ["VK_LSHIFT"])635}636def _keyToScancode(keyNameOrCode):637 keycode = virtualKeycodes.get(keyNameOrCode, keyNameOrCode)638 if not isinstance(keycode, int):639 raise ValueError('invalid key "%s"' % (keyName,))640 scancode = libwinpr.GetVirtualScanCodeFromVirtualKeyCode(keycode, 4)641 return scancode642def _preConnect(instance_p):643 return True644def _postConnect(instance_p):645 rv = libgdi.gdi_init(instance_p,646 CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_16BPP | CLRBUF_32BPP,647 ctypes.cast(NULL, BYTE_P))648 return True649class RDPConnection(fmbtgti.GUITestConnection):650 def __init__(self, hostport, resolution=None, connect=True):651 fmbtgti.GUITestConnection.__init__(self)652 self.instance = None653 self._hostport = hostport654 self._resolution = resolution655 self._connectionError = None656 if connect and not self.connect(hostport, resolution):657 raise RdpConnectionError('connecting to "%s" failed' % (hostport,))658 def connect(self, hostport=None, resolution=None):659 if hostport:660 self._hostport = hostport661 else:662 hostport = self._hostport663 if resolution:664 self._resolution = resolution665 else:666 resolution = self._resolution667 self._connectionError = None668 if ":" in hostport:669 try:670 self.host, port = hostport.split(":", 1)671 self.port = int(port)672 except ValueError:673 raise RdpConnectionError('invalid hostport (host[:port]) "%s"' % (hostport,))674 else:675 self.host = hostport676 self.port = 3389677 self.instance_p = libcore.freerdp_new()678 self.instance = self.instance_p.contents679 self.instance.PreConnect = RdppPreConnect(_preConnect)680 self.instance.PostConnect = RdppPostConnect(_postConnect)681 self.instance.VerifyCertificate = NULL682 self.instance.ReceiveChannelData = NULL683 self.instance.ContextNew = NULL684 self.instance.ContextFree = NULL685 libcore.freerdp_context_new(self.instance_p)686 self.context = self.instance.context.contents687 self.context.channels = libcore.freerdp_channels_new()688 self.settings = self.instance.settings.contents689 self.settings.RdpSecurity = True690 self.settings.TlsSecurity = False691 self.settings.NlaSecurity = False692 self.settings.ServerHostname = self.host693 self.settings.ServerPort = self.port694 self.settings.DisableEncryption = True695 self.settings.ColorDepth = 32696 self.settings.Workarea = False697 if resolution:698 width, height = resolution699 self.settings.DesktopWidth = width700 self.settings.DesktopHeight = height701 if libcore.freerdp_connect(self.instance_p):702 self._rfds = (VOID_P * 256)(0)703 self._wfds = (VOID_P * 256)(0)704 self._thread_lock = thread.allocate_lock()705 self._pipe_rfd, self._pipe_wfd = os.pipe()706 thread.start_new_thread(self._communication, ())707 return True708 else:709 return False710 def close(self):711 if self.instance:712 libcore.freerdp_channels_close(self.context.channels, self.instance_p)713 libcore.freerdp_channels_free(self.context.channels)714 libgdi.gdi_free(self.instance_p)715 libcore.freerdp_disconnect(self.instance_p)716 libcore.freerdp_free(self.instance_p)717 def error(self):718 rv = self._connectionError719 self._connectionError = None720 return rv721 def recvScreenshot(self, filename):722 gdi = self.context.gdi.contents723 w = gdi.width724 h = gdi.height725 with self._thread_lock:726 png_data = fmbtpng.raw2png(gdi.primary_buffer, w, h, fmt="RGBA")727 file(filename, "wb").write(png_data)728 return True729 def sendKeyDown(self, keyName, modifiers=[]):730 if modifiers:731 self.sendKeyDown(modifiers[0])732 try:733 self.sendKeyDown(keyName, modifiers[1:])734 finally:735 self.sendKeyUp(modifiers[0])736 else:737 scancode = _keyToScancode(keyName)738 libcore.freerdp_input_send_keyboard_event_ex(self.instance.input, True, scancode)739 return True740 def sendKeyUp(self, keyName, modifiers=[]):741 if modifiers:742 self.sendKeyDown(modifiers[0])743 try:744 self.sendKeyUp(keyName, modifiers[1:])745 finally:746 self.sendKeyUp(modifiers[0])747 else:748 scancode = _keyToScancode(keyName)749 libcore.freerdp_input_send_keyboard_event_ex(self.instance.input, False, scancode)750 return True751 def sendPress(self, keyName, modifiers=[]):752 for modKey in modifiers:753 self.sendKeyDown(modKey)754 self.sendKeyDown(keyName)755 self.sendKeyUp(keyName)756 for modKey in reversed(modifiers):757 self.sendKeyUp(modKey)758 return True759 def sendType(self, text):760 for char in text:761 if char in string.lowercase or char in string.digits:762 self.sendPress("VK_KEY_" + char.upper())...

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