没有按键的关键模拟 [英] Key simulation without pressing keys

查看:79
本文介绍了没有按键的关键模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



作为我项目的一部分,我需要在Vb.net中打印Active应用程序。例如,如果Web浏览器当前处于活动状态,那么它应该打印该网页。可以通过模拟按键(Ctrl + P而不实际按下)或使用打印库来完成。此应用程序由使用AutoHotKey的快捷方式触发,因此此过程在后台运行。这是代码..

Hello,

As a part of my project, I need to print Active application in Vb.net. For example, if web browser is currently active Application then it should print that web page. It can be done by simulating Key Press (Ctrl + P without actually pressing it) or using Print library. This application is triggered by Shortcut using AutoHotKey, So this process runs in background. Here is code..

 Public Class Class1

    Public Shared Sub Main()
        Dim filePath As String = "C:\Users\AG\Desktop\SCaptur.png"

        CMD.ToPDFCreator()
        CMD.PrintDocument()
        CMD.ChangeBack()

    End Sub

End Class

Public NotInheritable Class CMD

#Region " Methods "

    Public Shared Function ToPDFCreator()
        Dim p As Process = New Process()
        Dim pi As ProcessStartInfo = New ProcessStartInfo()
        pi.Arguments = " " + "/C" + " " + "RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n" + " " + "PDFCreator"
        pi.FileName = "cmd.exe"
        p.StartInfo = pi
        p.Start()
    End Function

    Public Shared Function PrintDocument()
        System.Windows.Forms.SendKeys.Send("^P")
    End Function

    Public Shared Function ChangeBack()
        Dim p As Process = New Process()
        Dim pi As ProcessStartInfo = New ProcessStartInfo()
        pi.Arguments = " " + "/C" + " " + "RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n" + " " + """" + "HP DeskJet" + """"
        pi.FileName = "cmd.exe"
        p.StartInfo = pi
        p.Start()
    End Function

#End Region

End Class

此代码显示错误:

SendKeys无法在此应用程序内运行,因为应用程序不处理Windows消息。更改应用程序以处理消息,或使用SendKeys.SendWait方法。



任何人都可以告诉我,如何解决此问题?

是否有其他方法可以打印活动应用程序?

This code show error:
SendKeys cannot run inside this application because the application is not handling Windows messages. Either change the application to handle messages, or use the SendKeys.SendWait method.

Can any one tell me, How to resolve this issue?
Is there any other method to print active application?

推荐答案

尝试System.Windows.Forms.SendKeys.Send(^(p))

不是资本P而是小p。

应该有效:)
Try System.Windows.Forms.SendKeys.Send("^(p)")
Not capital P but small p.
That should work :)


这篇关于没有按键的关键模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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