问题描述
我正在尝试开发Visual Basic控制台应用程序,以使用遗传算法优化结构.我偶尔使用的软件会弹出弹出窗口,以保存更新的结构.我想编写一段代码来模拟活动窗口上的按键操作(我想按Enter键),这样我就不必每隔15分钟手动按下一次Enter键.
I'm trying to develop a Visual Basic console application to optimise a structure using Genetic Algorithms. The software I'm using occasionally throws popups to save the updated structure. I want to write a piece of code that simulates key presses (I want to press the enter key) on the active window so that I don't have manually press the enter key every 15 minutes.
我尝试使用
SendKeys.SendWait({"ENTER"})
但是控制台应用程序中没有SendKeys.
but there's no SendKeys in Console Application.
推荐答案
使用我的 InputHelper库请按照以下步骤操作:
To use my InputHelper library follow these steps:
-
从GitHub下载库(不是源代码):
https://github.com/Visual-Vincent/InputHelper/releases
Download the library (not the source code) from GitHub:
https://github.com/Visual-Vincent/InputHelper/releases
在某处提取.zip
文件.
在Visual Studio中,右键单击Solution Explorer
中的项目,然后按Add Reference...
.
In Visual Studio, right-click your project in the Solution Explorer
and press Add Reference...
.
转到Browse
选项卡,找到从步骤2中提取的文件夹,然后选择InputHelper.dll
文件.
Go to the Browse
tab and locate the extracted folder from step 2, then select the InputHelper.dll
file.
现在再次执行步骤3,但这一次转到.NET
选项卡并导入System.Windows.Forms
(仅在使用控制台应用程序时才需要).
Now do step 3 again, but this time go to the .NET
tab and import System.Windows.Forms
(this is only needed if you are using a Console Application).
最后,通过将其写入代码文件的顶部,导入InputHelperLib
命名空间以及System.Windows.Forms
:
Finally, import the InputHelperLib
namespace as well as System.Windows.Forms
by writing this in the top of your code file:
Imports System.Windows.Forms
Imports InputHelperLib
现在,您可以使用InputHelper.Keyboard.PressKey()
方法以编程方式按下一个键:
Now you can use the InputHelper.Keyboard.PressKey()
method to programmatically press a key:
Imports System.Windows.Forms
Imports InputHelperLib
Module MainModule
Public Sub Main()
'Some code here...
InputHelper.Keyboard.PressKey(Keys.Enter)
'Some code here...
End Sub
End Module
只要用户仍然了解文件的用途,就可以重命名该文件.
You may rename the file as long as the user still understands what it is for.
InputHelper当前包括四个主要类别:
InputHelper currently consists of four main categories:
-
InputHelper.Hooks
:用于捕获系统范围的鼠标和键盘输入的类.例如,这可用于制作热键.请参见项目的Wiki 以获得实施帮助.
InputHelper.Keyboard
:模拟物理键盘输入/按键的方法.
InputHelper.Keyboard
: Methods for simulating physical keyboard input/key strokes.
InputHelper.Mouse
:模拟物理鼠标输入的方法.
InputHelper.Mouse
: Methods for simulating physical mouse input.
InputHelper.WindowMessages
:用于更虚拟地模拟鼠标和键盘输入的方法.这利用了窗口消息,可用于定位特定的窗口.
InputHelper.WindowMessages
: Methods for simulating mouse and keyboard input at a more virtual level. This utilizes window messages and can be used to target specific windows.
要浏览我的库的内容,请右键单击代码中的名称空间,然后按Go To Definition
.
To explore the contents of my library right-click the namespace in your code and press Go To Definition
.
这将打开Object Browser
,您可以在其中浏览我的库的内容,所有类型(类别")在左侧,方法/成员在右侧.
This will open the Object Browser
, in which you can browse the contents of my library, with all the types ("categories") on the left, and the methods/members on the right.
-
右键单击>转到定义
浏览InputHelperLib
的内容
Browsing InputHelperLib
's contents
这篇关于在Visual Basic控制台应用程序中发送按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!