Vb.net 捕获 Ctrl+C [英] Vb.net Capture Ctrl+C
问题描述
我想在有人使用 CtrlC 时进行捕捉,即使是在离焦时.我使用的是 Visual Basic 2010.
I want to capture when someone uses CtrlC even when off focus. im using Visual Basic 2010.
推荐答案
好的,我为您提供了一个经过验证有效的解决方案.不过,您将需要一个 C# 库,并且需要做一些额外的工作,但不会太多.创建一个 C# 类库并添加一个名为MyHooks"的类,并添加对 System.Windows.Forms.dll 和我链接到的库的引用.将使用它的主程序将引用此 C# 库和 System.Windows.Forms.
Okay, so I have a solution for you that I verified works. You will need a C# library though, and a little extra work is required, but not much. Create a C# class library and add a class called 'MyHooks' and add a reference to both System.Windows.Forms.dll and the library I linked you to. Your main program that will use this will reference this C# library and System.Windows.Forms.
namespace HookManager.Interface {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gma.UserActivityMonitor;
using System.Windows.Forms;
public static class MyHooks {
public static void HookControlC(KeyEventHandler keyDown, KeyEventHandler keyUp) {
HookManager.KeyDown += keyDown;
HookManager.KeyUp += keyUp;
}
}
}
现在在您的程序中可以执行以下操作:
Now in your program can do something like:
Imports hookmanager.interface
Imports System.Windows.Forms
Module Module1
Sub Main()
MyHooks.HookControlC(AddressOf ControlC_KeyDown, AddressOf ControlC_KeyUp)
While True
Application.DoEvents()
End While
End Sub
Private m_ControlKeyPressed As Boolean = False
Private Sub ControlC_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.KeyValue = 162 OrElse e.KeyValue = 163 Then
m_ControlKeyPressed = True
End If
If m_ControlKeyPressed Then
If e.KeyCode = Keys.C Then
Console.WriteLine("You captured, control c!")
Console.WriteLine(Clipboard.GetText())
End If
End If
End Sub
Private Sub ControlC_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
If m_ControlKeyPressed Then
If e.KeyValue = 162 OrElse e.KeyValue = 163 Then
m_ControlKeyPressed = False
End If
End If
End Sub
End Module
这篇关于Vb.net 捕获 Ctrl+C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!