Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 03-02-08   #1 (permalink)
News Fiend
 
intel nvidia

Join Date: Mar 2007
Posts: 94

Rep: 9 kyotejones Unknown
Unique Rep: 9
Trader Rating: 0
Default Sending keystrokes c#

So im trying to make a macros program and I am trying to send keystrokes to the active window.

I have so far pulling the the application to focus, and got the threading down, but just need to know how to send the active window keys. Any help would be appreciated.

I did build a program like this a while back but since then lost the HD and all the data. I remember using a very old method of importing the user32.dll and calling a function from that. Buts thats all I remember. I have tried using the newer method SendKeys but thats not working for me.
__________________
System: SCUD
CPU
Pentium C2D 2.4GHz
Motherboard
ASUS P5N32-E SLI
Memory
2x1Gb Balistix
Graphics Card
GeForce 7950 GT
Sound Card
SupremeFX (ADI 1988b)
Power Supply
ENERMAX Liberty 620W
Case
RAIDMAX SMILODON ATX
CPU cooling
ARCTIC COOLING Freezer 7
GPU cooling
Passive Heat Sink + CPU Fan
OS
Win XP Pro
Monitor
2x20" Samsung SyncMaster
kyotejones is offline   Reply With Quote
Old 03-03-08   #2 (permalink)
News Fiend
 
intel nvidia

Join Date: Mar 2007
Posts: 94

Rep: 9 kyotejones Unknown
Unique Rep: 9
Trader Rating: 0
Default

I got what I needed so you can ignore this now. Unless someone wants to share some input about the subject. Thats always appreciated.
__________________
System: SCUD
CPU
Pentium C2D 2.4GHz
Motherboard
ASUS P5N32-E SLI
Memory
2x1Gb Balistix
Graphics Card
GeForce 7950 GT
Sound Card
SupremeFX (ADI 1988b)
Power Supply
ENERMAX Liberty 620W
Case
RAIDMAX SMILODON ATX
CPU cooling
ARCTIC COOLING Freezer 7
GPU cooling
Passive Heat Sink + CPU Fan
OS
Win XP Pro
Monitor
2x20" Samsung SyncMaster
kyotejones is offline   Reply With Quote
Old 03-12-08   #3 (permalink)
New to Overclock.net
 
Join Date: Mar 2008
Posts: 1

Rep: 0 Manvinder Unknown
Unique Rep: 0
Trader Rating: 0
Default Need your help

Quote:
Originally Posted by kyotejones View Post
I got what I needed so you can ignore this now. Unless someone wants to share some input about the subject. Thats always appreciated.
Hi

I am also working on similar app. So please give some hint regarding how to send
keystrokes to some other application.
Manvinder is offline   Reply With Quote
Old 04-16-08   #4 (permalink)
News Fiend
 
intel nvidia

Join Date: Mar 2007
Posts: 94

Rep: 9 kyotejones Unknown
Unique Rep: 9
Trader Rating: 0
Default

Should have checked back faster. Well all I ended up doing was using SendKeys.SendWait(). The reason it wasn't working for me before was because I was trying to send keys to a window that was still being pulled to focus. So I added a thread delay of 1 second before I sent the keys.

example:
Code:
using System.Diagnostics;
using System.Threading;

public partial class CHOPPA
{

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private Thread thrTyping;

private void startThread()
{
    ThreadStart ts = new ThreadStart(sendKeys);
    thrTyping = new Thread(ts);
    thrTyping.Start();
}

private void sendKeys()
{
    while (condition)
    {
        //find and bring the application i need to focus
        Process[] processes = Process.GetProcessesByName("App_Name");
        foreach (Process proc in processes)
        {
            SetForegroundWindow(proc.MainWindowHandle);
        }

        //sleep the thread before I send it the keys for at least 1 second
        Thread.Sleep(1000);
        SendKeys.SendWait("{F4}");
    }
}
}
sendKeys is the method that sends my application the keys. Now obviously there are probably some mistakes here but its an example, so be gentle if you have comments.
__________________
System: SCUD
CPU
Pentium C2D 2.4GHz
Motherboard
ASUS P5N32-E SLI
Memory
2x1Gb Balistix
Graphics Card
GeForce 7950 GT
Sound Card
SupremeFX (ADI 1988b)
Power Supply
ENERMAX Liberty 620W
Case
RAIDMAX SMILODON ATX
CPU cooling
ARCTIC COOLING Freezer 7
GPU cooling
Passive Heat Sink + CPU Fan
OS
Win XP Pro
Monitor
2x20" Samsung SyncMaster
kyotejones is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 04:00 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.32199 seconds with 8 queries