it suppose send a keystroke to the application it focused...
here is my code:
i did that only if FT_client is focused send a keystroke with the Senkeys method:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Diagnostics;
using System.Timers;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
using System.Net.Mail;
using Microsoft.Win32;
using System.Security.Principal;
namespace WindowsInput
{
class Program
{
public static Process[] ft = Process.GetProcessesByName("FT_Client");
public static bool check=false;
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("User32")]
private static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("User32")]
private static extern IntPtr GetForegroundWindow();
public static Boolean checkProcesses(Process[] z)
{
IntPtr k = GetForegroundWindow();//get the focused process handle
foreach (Process p in z)
{
if (k.Equals(p.MainWindowHandle))
{
return true;
}
}
return false;
}
public static void OnTimedEvent(object source, EventArgs e)
{
if (checkProcesses(ft))
{
/*SetForegroundWindow(ft.MainWindowHandle);*/
SendKeys.SendWait("W");
InputSimulator.SimulateKeyPress(VirtualKeyCode.SPA CE);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_ W);
}
}
static void Main(string[] args)
{
IntPtr p = ft[0].MainWindowHandle;
System.Timers.Timer timer;
timer = new System.Timers.Timer();
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
timer.AutoReset = true;
timer.Interval = 5000;
timer.Start();
Application.Run();
GC.KeepAlive(timer);
}
}
}
it sends the key like "W" or whatever but only if im in the texbox in fantasy tennis or in the loby somehow it doest really press w when im in lifewoods tring to use qs...i mean it send the key "w" but it doesnt press w...
it has a timer with interval i can change it to whatever i want ( its in miliseconds - 1000 mil = 1 second)
nobody can help me? i thought we have programmers here...