mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-07-12 20:42:52 +08:00
界面自动化添加启用禁用元素功能
This commit is contained in:
parent
cf4d38c3b1
commit
7a7cb8dd54
@ -94,6 +94,9 @@ public class AutomationManager
|
||||
[DllImport("user32.dll")]
|
||||
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool EnableWindow(IntPtr hWnd, bool bEnable);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct RECT
|
||||
{
|
||||
@ -121,6 +124,7 @@ public class AutomationManager
|
||||
private static Form overlayForm;
|
||||
private static Form previewForm;
|
||||
private static AutomationElement lastElement;
|
||||
private static Point lastCursorPos;
|
||||
private static bool completed;
|
||||
|
||||
private static CacheRequest CreateCacheRequest()
|
||||
@ -318,6 +322,11 @@ public class AutomationManager
|
||||
SendKeys(GetTargetElement(args), keys);
|
||||
break;
|
||||
|
||||
case "enable":
|
||||
bool enable = GetArgumentValue(args, "-enable") == "true";
|
||||
EnableElement(GetTargetElement(args), enable);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception(string.Format("不支持的操作类型: {0}", type));
|
||||
}
|
||||
@ -586,18 +595,10 @@ public class AutomationManager
|
||||
- {DIVIDE} - 数字键盘除号键
|
||||
- {NUMPAD0} - {NUMPAD9} - 数字键盘数字键
|
||||
|
||||
修饰键:
|
||||
+ (加号) - SHIFT
|
||||
^ (脱字号) - CTRL
|
||||
% (百分号) - ALT
|
||||
|
||||
12. enable - 启用/禁用元素
|
||||
参数: -xpath <XPath路径> -enable <true/false> [-window <窗口句柄>]
|
||||
示例:
|
||||
- 输入文本: -keys ""Hello""
|
||||
- 按Enter键: -keys ""{ENTER}""
|
||||
- 按Ctrl+C: -keys ""^c""
|
||||
- 按Ctrl+Home: -keys ""^{HOME}""
|
||||
- 按Alt+F4: -keys ""%{F4}""
|
||||
- 按Shift+Tab: -keys ""+{TAB}""
|
||||
- 启用按钮: -xpath ""//Button[@Name='确定']"" -enable true
|
||||
|
||||
通用参数:
|
||||
-window <窗口句柄> 指定要操作的窗口,如果不指定则使用当前活动窗口
|
||||
@ -1127,6 +1128,23 @@ public class AutomationManager
|
||||
};
|
||||
}
|
||||
|
||||
private static void EnableElement(AutomationElement element, bool enable)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
throw new Exception("元素不能为空");
|
||||
}
|
||||
try
|
||||
{
|
||||
EnableWindow((IntPtr)element.Current.NativeWindowHandle, enable);
|
||||
Console.WriteLine("true");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("无法更改元素的启用/禁用状态: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ClickElement(AutomationElement element)
|
||||
{
|
||||
if (element == null)
|
||||
@ -1310,7 +1328,7 @@ public class AutomationManager
|
||||
completed = false; // 使用静态字段
|
||||
Rectangle lastRect = Rectangle.Empty;
|
||||
lastElement = null;
|
||||
Point lastCursorPos = new Point();
|
||||
lastCursorPos = new Point();
|
||||
AutomationElement taskbarElement = null;
|
||||
List<AutomationElement> taskbarChildren = null;
|
||||
|
||||
@ -1474,12 +1492,7 @@ public class AutomationManager
|
||||
{
|
||||
try
|
||||
{
|
||||
mouseTimer.Stop();
|
||||
overlayForm.Hide();
|
||||
previewForm.Hide();
|
||||
|
||||
InspectElementInfo(lastElement, lastCursorPos);
|
||||
completed = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -1487,8 +1500,7 @@ public class AutomationManager
|
||||
}
|
||||
finally
|
||||
{
|
||||
overlayForm.Close();
|
||||
previewForm.Close();
|
||||
stopInspect();
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -1684,6 +1696,7 @@ public class AutomationManager
|
||||
Clipboard.SetText(lastElement.Current.Name);
|
||||
if (e.KeyChar == 'x' || e.KeyChar == 'X')
|
||||
{
|
||||
InspectElementInfo(lastElement, lastCursorPos);
|
||||
stopInspect();
|
||||
}
|
||||
}
|
||||
@ -1694,6 +1707,4 @@ public class AutomationManager
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ async function runAutomation(
|
||||
break;
|
||||
|
||||
case "select":
|
||||
if (params.item) {
|
||||
if (params.item !== undefined) {
|
||||
args.push("-item", params.item);
|
||||
}
|
||||
break;
|
||||
@ -76,7 +76,7 @@ async function runAutomation(
|
||||
break;
|
||||
|
||||
case "scroll":
|
||||
if (params.direction) {
|
||||
if (params.direction !== undefined) {
|
||||
args.push("-direction", params.direction);
|
||||
}
|
||||
if (params.amount !== undefined) {
|
||||
@ -85,9 +85,6 @@ async function runAutomation(
|
||||
break;
|
||||
|
||||
case "wait":
|
||||
if (params.condition) {
|
||||
args.push("-condition", params.condition);
|
||||
}
|
||||
if (params.timeout !== undefined) {
|
||||
args.push("-timeout", params.timeout);
|
||||
}
|
||||
@ -100,10 +97,16 @@ async function runAutomation(
|
||||
break;
|
||||
|
||||
case "sendkeys":
|
||||
if (params.keys) {
|
||||
if (params.keys !== undefined) {
|
||||
args.push("-keys", params.keys);
|
||||
}
|
||||
break;
|
||||
|
||||
case "enable":
|
||||
if (params.enable !== undefined) {
|
||||
args.push("-enable", params.enable);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
let error;
|
||||
@ -144,4 +147,5 @@ module.exports = {
|
||||
focus: (...args) => runAutomation("focus", ...args),
|
||||
highlight: (...args) => runAutomation("highlight", ...args),
|
||||
sendkeys: (...args) => runAutomation("sendkeys", ...args),
|
||||
enable: (...args) => runAutomation("enable", ...args),
|
||||
};
|
||||
|
@ -491,6 +491,28 @@ export const windowsCommands = {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.windows.automation.enable",
|
||||
label: "启用/禁用元素",
|
||||
icon: "toggle_on",
|
||||
config: [
|
||||
{
|
||||
component: "OptionEditor",
|
||||
options: {
|
||||
enable: {
|
||||
component: "ButtonGroup",
|
||||
options: [
|
||||
{ label: "启用", value: true },
|
||||
{ label: "禁用", value: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
defaultValue: {
|
||||
enable: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.windows.automation.expand",
|
||||
label: "展开/折叠",
|
||||
@ -559,13 +581,6 @@ export const windowsCommands = {
|
||||
{
|
||||
component: "OptionEditor",
|
||||
options: {
|
||||
condition: {
|
||||
label: "条件",
|
||||
component: "VariableInput",
|
||||
icon: "filter_alt",
|
||||
width: 8,
|
||||
placeholder: "name=xx;type=Button",
|
||||
},
|
||||
timeout: {
|
||||
label: "超时(秒)",
|
||||
component: "NumberInput",
|
||||
|
Loading…
x
Reference in New Issue
Block a user