如何基于批处理或Powershell中按下的键做出IF语句? [英] How do I make an IF statement based on which keys are pressed in batch or powershell?

查看:33
本文介绍了如何基于批处理或Powershell中按下的键做出IF语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近有了一只很棒的鼠标,发现背面&前进按钮几乎没用.但是,它们的位置很好,所以我决定尝试编写一些程序.

I recently got an awesome mouse and found the back & forward buttons nearly useless. However, they were well placed so I decided to try and make a little program.

是否可以制作将执行以下操作的PowerShell/批处理程序:
1.部署将由键盘快捷键(ALT + RIGHT和ALT + LEFT)触发的if语句
2.一旦触发了if语句,就好像没有任何反应一样拒绝键(很可能是将键发送到脚本而不是当前程序)
3.发送新密钥以完成工作.

Is it possible to make a PowerShell/Batch program that will:
1. Deploy an if statement that will be triggered by a keyboard shortcut (ALT + RIGHT & ALT + LEFT)
2. Once the if statement is triggered, reject the keys as if nothing happened (most likely by sending the keys to the script instead of the current program)
3. Send new keys to do the job.

这就像重新映射前进/后退按钮-无需任何软件,而只是一种自制解决方案.

This would be like remapping the forward/back button - without any software, just a home-made solution.

FYI-

这不起作用:
如何检查是否在批处理中按下了键?

推荐答案

您可以使用Powershell!.

您需要使用

You'd need to use a global windows hook. Looks like it would be either the WH_KEYBOARD_LL or WH_KEYBOARD hook.

为此,您的PS脚本将需要P/调用多个Win32 API,并将Win32结构映射到托管结构.

To do that your PS script will need to P/Invoke several Win32 APIs and map Win32 structures to managed structures.

我从来没有对Windows挂钩做过任何事情,但是看起来似乎有点复杂(如果不是很认真的话).而且从PS进行操作可能会使它比C/C ++复杂.

I've never done anything with Windows hooks, but offhand it seems like this would be moderately (if not seriously) complicated. And doing it from PS probably makes it more complicated than it would be from C/C++.

但是我迷上了来自PS的WndProc ,我发现比C ++更容易实现所需的功能.从长远来看,这是最初的障碍,因为PS中实现了许多功能.因此,这完全取决于您的情况.

However I have hooked a WndProc from PS where I found it easier to implement the functionality I needed than in C++. In the long run it was worth the initial hurdles because a lot of functionality was implemented in PS. So it all depends on your circumstances.

这篇关于如何基于批处理或Powershell中按下的键做出IF语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆