-2
我想做一個應用程序,它會替換每個輸入,如果它匹配的模式。 例如,如果用戶按LeftMouseButton + Ctrl,程序會將其更改爲右鍵單擊,並僅將其發送到當前活動窗口或捕獲窗口。替換輸入鉤子
問題是我該如何解決它在C#中?
我想做一個應用程序,它會替換每個輸入,如果它匹配的模式。 例如,如果用戶按LeftMouseButton + Ctrl,程序會將其更改爲右鍵單擊,並僅將其發送到當前活動窗口或捕獲窗口。替換輸入鉤子
問題是我該如何解決它在C#中?
您需要實現這樣的類,您必須調整它以支持鼠標點擊以滿足您的需求,但它應該會向您顯示一些第一步。
public class KeyConverter {
//All conversions are stored in this dictionary.
private Dictionary<Keys, Keys> conversions = new Dictionary<Keys, Keys>();
public KeyConverter() {
//this conversion will convert every Ctrl+C signal into Ctrl+V
conversions.Add(Keys.C | Keys.Control, Keys.V | Keys.Control);
}
public Keys Convert(Keys keys) {
if (conversions.ContainsKey(keys))
return conversions[keys];
else
return keys; //return the input if no conversion is available
}
}
將您需要的轉換添加到轉換字典中。訂閱觀察擊鍵和調用方法的事件使用當前按下的鍵進行轉換。 使用
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
public void SendKey(Keys keys){
foreach(Keys key in Enum.GetValues(typeof(Keys)))
if(keys.HasFlag(key))
keybd_event((byte)key, 0, 0, 0); //press key
foreach(Keys key in Enum.GetValues(typeof(Keys)))
if(keys.HasFlag(key))
keybd_event((byte)key, 0, 0x2, 0); // release key
}
,問題是..... – inspite
[你嘗試過什麼]發送鍵返回到您的系統(http://whathaveyoutried.com)?你卡在哪裏?向我們展示您當前的代碼並解釋問題是在此提問的最佳方式。 – Oded
我只有一個來自互聯網的鍵盤和鼠標鉤子代碼(庫,類結構)。 – androbin