是我喜欢做的事: 我应该在后台捕获KEYUP和keydowns运行程序。在一个特定的keydown应该粘贴一些文本到当前活动窗口。
键的拍摄是工作,但我怎么能文本粘贴到当前活动窗口? (鼠标位置)
在code,我到目前为止,你可以在这里看到:
使用系统;
使用System.IO;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data这;
使用System.Drawing中;
使用System.Linq的;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms的;
使用了System.Runtime.InteropServices;
使用工具;
命名空间Developper_Dashboard
{
公共部分类Form1中:形态
{
globalKeyboardHook GKH =新globalKeyboardHook();
私人布尔IsADown = FALSE;
私人布尔IsBDown = FALSE;
公共Form1中()
{
的InitializeComponent();
}
私人无效Form1_Load的(对象发件人,EventArgs的)
{
this.Opacity = 0;
gkh.HookedKeys.Add(Keys.LControlKey);
gkh.HookedKeys.Add(Keys.LShiftKey);
gkh.HookedKeys.Add(Keys.Q);
gkh.KeyDown + =新KeyEventHandler(gkh_KeyDown);
gkh.KeyUp + =新KeyEventHandler(gkh_KeyUp);
}
无效gkh_KeyUp(对象发件人,KeyEventArgs E)
{
如果(e.Key code == Keys.Control)
{
IsADown = FALSE;
}
如果(e.Key code == Keys.LShiftKey)
{
IsBDown = FALSE;
}
如果(IsADown!| IsBDown)
{
this.Opacity = 0;
}
//e.Handled = TRUE;
}
无效gkh_KeyDown(对象发件人,KeyEventArgs E)
{
如果(e.Key code == Keys.LControlKey)
{
IsADown = TRUE;
}
如果(e.Key code == Keys.LShiftKey)
{
IsBDown = TRUE;
}
如果(IsADown&安培;&安培; IsBDown)
{
this.Opacity = 1;
}
如果(IsADown&安培;&安培; IsBDown和放大器;&安培; e.Key code == Keys.Q)
{
//发送到剪贴板当前活动窗口
}
}
}
}
解决方案
使用的 SendKeys类来发送Ctrl + V将当前窗口是这样的:
SendKeys.Send({^} V);
what I like to do: I have a program that should run in background and capture keyup and keydowns. On a specific keydown it should paste some text into the current active window.
The capturing of the keys is working but how can I paste text into the current active window? (mouse position)
The code that I have so far you can see here:
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Utilities;
namespace Developper_Dashboard
{
public partial class Form1 : Form
{
globalKeyboardHook gkh = new globalKeyboardHook();
private bool IsADown = false;
private bool IsBDown = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Opacity = 0;
gkh.HookedKeys.Add(Keys.LControlKey);
gkh.HookedKeys.Add(Keys.LShiftKey);
gkh.HookedKeys.Add(Keys.Q);
gkh.KeyDown += new KeyEventHandler(gkh_KeyDown);
gkh.KeyUp += new KeyEventHandler(gkh_KeyUp);
}
void gkh_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Control)
{
IsADown = false;
}
if (e.KeyCode == Keys.LShiftKey)
{
IsBDown = false;
}
if (!IsADown | !IsBDown)
{
this.Opacity = 0;
}
//e.Handled = true;
}
void gkh_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.LControlKey)
{
IsADown = true;
}
if (e.KeyCode == Keys.LShiftKey)
{
IsBDown = true;
}
if (IsADown && IsBDown)
{
this.Opacity = 1;
}
if (IsADown && IsBDown && e.KeyCode == Keys.Q)
{
//Send Clipboard to current active window
}
}
}
}
解决方案
Use the SendKeys Class to send Ctrl+V to the current window like this:
SendKeys.Send("{^}V");