AutoHotKey-Script应该从在Linux中运行的AutoKey给出的剪贴板中读取按下并释放的Key,ActiveTitle,ActiveClass。
这是一个AutoHotKey包装器,用于在Linux中使用AutoHotKey。 使用AutoKey,AutoHotKey和wine(Alpha版:https://github.com/sl5net/AutoHotKey4Linux)
当前的问题是Ahk工具提示不显示任何内容,也没有报告错误。
剪贴板看起来像这样(每一行都是一个例子):
<AutoKey:active_title=read_key_title_class_from_cllipboard.ahk - Mousepad,active_class=mousepad.Mousepad,press_key='s'>
<AutoKey:active_title=read_key_title_class_from_cllipboard.ahk - Mousepad,active_class=mousepad.Mousepad,release_key='s'>
<AutoKey:active_title=read_key_title_class_from_cllipboard.ahk - Mousepad,active_class=mousepad.Mousepad,press_key=Key.ctrl>
结果应该在工具提示中可见。
当前的AutoHotKey脚本:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn
#SingleInstance Force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode 2
SetBatchLines, -1
; WinGetTitle, at, A ; MsgBox, The active window is "%Title%".
; <AutoKey:active_title=active_title,active_class=active_class>
tOld := ""
cOld := ""
keyOld := ""
; Expected Examples of Version 1:
; <AutoKey:active_title=*/home/seeh/skripts/ahk/read_key_title_class_from_cllipboard.ahk - Mousepad,active_class=mousepad.Mousepad,key=Key.up>
; <AutoKey:active_title=*/home/seeh/skripts/ahk/read_key_title_class_from_cllipboard.ahk - Mousepad,active_class=mousepad.Mousepad,key=Key.ctrl>
; <AutoKey:active_title=*/home/seeh/skripts/ahk/read_key_title_class_from_cllipboard.ahk - Mousepad,active_class=mousepad.Mousepad,key='f'>
; <AutoKey:active_title=*/home/seeh/skripts/ahk/read_key_title_class_from_cllipboard.ahk - Mousepad,active_class=mousepad.Mousepad,press_key=Key.ctrl>
cbBackup := clipboard
while(1)
{
cb = %clipboard%
; press_key ; release_key
; (?<pressORrelease>(press|release))_key
; FoundPos := RegExMatch(cb, "O)<AutoKey:active_title=(?<active_title>[^,>]*),active_class=(?<active_class>[^,>]*),key='(?<key>[^,>']*)'>", SubPat) ; The starting "O)" turns SubPat into an object.
FoundPos := RegExMatch(cb, "O)<AutoKey:active_title=(?<active_title>[^,>]*),active_class=(?<active_class>[^,>]*),(?<pressORrelease>(press|release))_key=(?<key>[^,>]*)>", SubPat) ; The starting "O)" turns SubPat into an object.
;if(FoundPos && (tOld <> SubPat["active_title"] || cOld <> SubPat["active_class"])){
if(FoundPos){
if(keyOld <> SubPat["key"]){
clipboard := cbBackup
keyOld := SubPat["key"]
tOld := SubPat["active_title"]
cOld := SubPat["active_class"]
tooltip, % "tit=" SubPat["active_title"] "`nclass=" SubPat["active_class"] "`npressORrelease=" SubPat["pressORrelease"] "`nkey=" SubPat["key"] "`nBackup=" cbBackup, 350, 5
}
}else{
cbBackup := cb
}
;FoundPos:=0
Sleep,150
}
tooltip,
; FoundPosFoundPos
; TEST asdfasdf fdsasdf fds
; <AutoKey:active_title=*/home/seeh/skripts/ahk/read_key_title_class_from_cllipboard.ahk - Mousepad,active_class=mousepad.Mousepad,press_key=Key.ctrl>
; rwar
自动键脚本:
# this script needs to be started from AutoKey
import subprocess
import threading
import time
import re
from pynput.keyboard import Key, Listener
from typing import NamedTuple, Union, List
from autokey import iomediator
def on_press(key): # Example: <AutoKey:active_title=AutoKey,active_class=autokey-gtk.Autokey-gtk,key='k'>
if key == Key.esc:
return False
print('{0} pressed'.format(key))
key2 = '{0}'.format(key)
active_title = window.get_active_title()
active_class = window.get_active_class()
str = "<AutoKey:active_title=" + active_title + ",active_class=" + active_class + ",press_key=" + key2 + ">"
# v <AutoKey:active_title=AutoKey,active_class=autokey-gtk.Autokey-gtk,key=Key.ctrl>v<AutoKey:active_title=AutoKey,active_class=autokey-gtk.Autokey-gtk,key=Key.ctrl>
clipboard.fill_clipboard(str)
# strLen = len(str)
# clipboard.fill_clipboard("testsetstt") # <======= works!!! inside of AutoKey GUIx
tOld = active_title
cOld = active_class
# clipboardBackup = clipboard.get_clipboard()
# time.sleep(0.1)
# time.sleep(0.2)
# clipboard.fill_clipboard(clipboardBackup)
def on_release(key):
if key == Key.esc:
return False
print('{0} pressed'.format(key))
key2 = '{0}'.format(key)
active_title = window.get_active_title()
active_class = window.get_active_class()
str = "<AutoKey:active_title=" + active_title + ",active_class=" + active_class + ",release_key=" + key2 + ">"
# v <AutoKey:active_title=AutoKey,active_class=autokey-gtk.Autokey-gtk,key=Key.ctrl>v<AutoKey:active_title=AutoKey,active_class=autokey-gtk.Autokey-gtk,key=Key.ctrl>
clipboard.fill_clipboard(str)
# strLen = len(str)
# clipboard.fill_clipboard("testsetstt") # <======= works!!! inside of AutoKey GUIx
tOld = active_title
cOld = active_class
# Collect events until released tkk j dea
with Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()