+ xvpar = [xvkbd_exe]
+ if qt_frontend == 'QT5':
+ xvpar.extend(["-jump-pointer", "-no-back-pointer"])
+ else:
+ xvpar.extend(["-xsendevent"])
+ if lyx_other_window_name is None:
+ xvpar.extend(["-window", lyx_window_name])
+ else:
+ xvpar.extend(["-window", lyx_other_window_name])
+ xvpar.extend(["-delay", actual_delay, "-text", keystr])
+ print("Sending \"" + keystr + "\"")
+ subprocess.call(xvpar, stdout = FNULL, stderr = FNULL)
+ sys.stdout.flush()
+
+Axreg = re.compile(r'^(.*)\\Ax([^\\]*)(.*)$')
+returnreg = re.compile(r'(\\\[[A-Z][a-z]+\])(.*)$')
+
+# recursive wrapper around sendKeystringLocal()
+# handling \Ax-entries
+def sendKeystringAx(line, LYX_PID):
+ global key_delay
+ saved_delay = key_delay
+ m = Axreg.match(line)
+ if m:
+ prefix = m.group(1)
+ content = m.group(2)
+ rest = m.group(3);
+ if prefix != "":
+ # since (.*) is greedy, check prefix for '\Ax' again
+ sendKeystringAx(prefix, LYX_PID)
+ sendKeystringLocal('\Ax', LYX_PID)
+ time.sleep(0.1)
+ m2 = returnreg.match(rest)
+ if m2:
+ line = m2.group(2)
+ ctrlk = m2.group(1)
+ key_delay = "1"
+ sendKeystringLocal(content + ctrlk, LYX_PID)
+ key_delay = saved_delay
+ time.sleep(controlkey_delay)
+ if line != "":
+ sendKeystringLocal(line, LYX_PID)
+ else:
+ if content != "":
+ sendKeystringLocal(content, LYX_PID)
+ if rest != "":
+ sendKeystringLocal(rest, LYX_PID)
+ else:
+ if line != "":
+ sendKeystringLocal(line, LYX_PID)
+
+specialkeyreg = re.compile(r'(.+)(\\[AC]([a-zA-Z]|\\\[[A-Z][a-z]+\]).*)$')
+# Split line at start of each meta or controll char
+
+def sendKeystringAC(line, LYX_PID):
+ m = specialkeyreg.match(line)
+ if m:
+ first = m.group(1)
+ second = m.group(2)
+ sendKeystringAC(first, LYX_PID)
+ sendKeystringAC(second, LYX_PID)
+ else:
+ sendKeystringAx(line, LYX_PID)
+
+controlkeyreg = re.compile(r'^(.*\\\[[A-Z][a-z]+\])(.*\\\[[A-Z][a-z]+\])(.*)$')
+# Make sure, only one of \[Return], \[Tab], \[Down], \[Home] etc are in one sent line
+# e.g. split the input line on each keysym
+def sendKeystringRT(line, LYX_PID):
+ m = controlkeyreg.match(line)
+ if m:
+ first = m.group(1)
+ second = m.group(2)
+ third = m.group(3)
+ sendKeystringRT(first, LYX_PID)
+ time.sleep(controlkey_delay)
+ sendKeystringRT(second, LYX_PID)
+ time.sleep(controlkey_delay)
+ if third != "":
+ sendKeystringRT(third, LYX_PID)