Hey guys ive been working on my first c# program and im finding it rather difficult at the moment. I have got as far as the code below, But i am having trouble getting it to send key strokes to either a specified process or a non active window by window title or process name.
These past few days ive been searching and found that i need to re-write my code to use different API's, But i was hoping there may be a short code snippet i can put at the top of the code that will send to only a certain process name.
I would like the key strokes to be sent while the window is minimized / not active.
Example, :
if process name = notepad, sendkeys;
if process name is not notepad, do nothing
What my program does is.
#1 - Checks if notepad is open, If not, disabled button1
#2 - If notpad is open, Every 6 seconds it sends the keys that i input into the textbox
This is my current code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.timer1.Interval = 6000;
this.timer1.Enabled = false;
timer2.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private Int32 state = 0;
private void timer1_Tick(object sender, EventArgs e)
{
SendKeys.Send(this.textBox1.Text);
}
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
this.timer1.Enabled = false;
}
private void timer2_Tick(object sender, EventArgs e)
{
{
System.Diagnostics.Process[] myprocess = System.Diagnostics.Process.GetProcessesByName("notepad");
if (myprocess.Length != 0)
{
button1.Enabled = true;
}
else
{
button1.Enabled = false;
}
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}