gpt4 book ai didi

linux - 调用键盘按键,通过 proc - tcl 中的过程(函数)

转载 作者:太空宇宙 更新时间:2023-11-04 04:55:05 24 4
gpt4 key购买 nike

在互联网上,我到目前为止只能找到与按键相关的事件与前端按钮关联的相反情况,而不是调用按键的前端按钮。明白了吗?!看:

#!/usr/bin/env wish

button .b1 -text Hello -underline 0
button .b2 -text World -underline 0
bind . {.b1 flash; .b1 invoke}
bind . {.b2 flash; .b2 invoke}
pack .b1 .b2

说明 - 如果按 H 按钮,Hello 按钮将会闪烁。 W 也会产生同样的效果;世界

我想要前端 [GUI] 按钮来模拟击键,例如 - F1

enter image description here

This Print Screen software is mp3blaster - learn more..

<小时/>

This Print Screen is a GUI what are developer are work:

enter image description here

我一两周前就问过这个问题。由于我没有得到任何貌似合理的答案,我不知道是否可能,或者没有人知道,或者没人关心。

我想发送 UNIX GNU/Linux 下的非 tcl/tk 应用程序一些 key 一个非常简单的工具栏控件。对于申请必须是就像在键盘上敲击这些键一样。在 Visual Basic 中该函数称为SendKey。可以用 tcl/tk 做到这一点吗?

我将描述如何使用 Windows Script Host 和 tcom 执行此操作:

在此示例中,Tcl 脚本启动记事本并将 key 发送到应用程序。

软件包需要 tcom

configure wshShell [:: tcom :: bind "WScript.Shell"]
set taskId [$ wshShell Run "notepad.exe"]
$ wshShell AppActivate $ taskId
after 500
$ wshShell SendKeys "The quick brown fox jumped \ n"
$ wshShell SendKeys "{TAB} about the lazy dog."
:: tcom :: release $ wshShell
<小时/>

在 UNIX 上; Linux如何实现这一点???可以通过focus方法、反向bind或第三方应用程序xvkbdxbindkeysxkeycapsxevxjoypad等...如果tcl/tk没有内置命令,该使用哪一个以及如何使用?!

如果有人知道和/或可以澄清我,我将不胜感激。

最佳答案

xdotool ( http://www.semicomplete.com/projects/xdotool/ ) 可以帮助完成该任务。

下面是一个简短的代码片段,当单击 Tk 按钮时,会将 Ctrl+Tab 发送到 Chrome:

#!/usr/bin/env wish

#
# Focus window named $window_name and send the specified key sequence.
#
proc send_key {window_name key_sequence} {
foreach wid [exec xdotool search --name $window_name] {
if {![catch {exec xdotool windowfocus $wid}]} {
exec xdotool key $key_sequence
}
}
}

button .f1 \
-text "Send Ctrl+Tab to Chrome (cycle through browser tabs)" \
-command {send_key chrome ctrl+Tab}
pack .f1

在向窗口发送按键序列之前,您必须先聚焦窗口,这有点问题。

关于linux - 调用键盘按键,通过 proc - tcl 中的过程(函数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49255962/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com