- subprocess.call([xvkbd_exe, "-no_root", "-wait_idle", lyx_pid,
- "-xsendevent", "-window", lyx_window_name,
- "-delay", actual_delay, "-text", keystr], stdout = FNULL, stderr = FNULL)
+ 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()
+
+def extractmultiple(line, regex):
+ #print("extractmultiple " + line)
+ res = ["", ""]
+ m = regex.match(line)
+ if m:
+ chr = m.group(1)
+ if m.group(2) == "":
+ res[0] = chr
+ res[1] = ""
+ else:
+ norm = extractmultiple(m.group(2), regex)
+ res[0] = chr + norm[0]
+ res[1] = norm[1]
+ else:
+ res[0] = ""
+ res[1] = line
+ return res
+
+normal_re = re.compile(r'^([^\\]|\\\\)(.*)$')
+def extractnormal(line):
+ # collect non-special chars from start of line
+ return extractmultiple(line, normal_re)
+
+modifier_re = re.compile(r'^(\\[CAS])(.+)$')
+def extractmodifiers(line):
+ # collect modifiers like '\\A' at start of line
+ return extractmultiple(line, modifier_re)
+
+special_re = re.compile(r'^(\\\[[A-Z][a-z0-9]+\])(.*)$')
+def extractsingle(line):
+ # check for single key following a modifier
+ # either ascii like 'a'
+ # or special like '\[Return]'
+ res = [False, "", ""]
+ m = normal_re.match(line)
+ if m:
+ res[0] = False
+ res[1] = m.group(1)
+ res[2] = m.group(2)
+ else:
+ m = special_re.match(line)
+ if m:
+ res[0] = True
+ res[1] = m.group(1)
+ res[2] = m.group(2)
+ else:
+ die(1, "Undecodable key for line \'" + line + "\"")
+ return res
+
+def sendKeystring(line, LYX_PID):
+ if line == "":
+ return
+ normalchars = extractnormal(line)
+ line = normalchars[1]
+ if normalchars[0] != "":
+ sendKeystringLocal(normalchars[0], LYX_PID)
+ if line == "":
+ return
+ modchars = extractmodifiers(line)
+ line = modchars[1]
+ if line == "":
+ die(1, "Missing modified key")
+ modifiedchar = extractsingle(line)
+ line = modifiedchar[2]
+ special = modchars[0] != "" or modifiedchar[0]
+ sendKeystringLocal(modchars[0] + modifiedchar[1], LYX_PID)
+ if special:
+ # give the os time to update the status info (in /proc)
+ time.sleep(controlkey_delay)
+ sendKeystring(line, LYX_PID)