CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

C# Stimulation mouse / keyboard! topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 08-30-2010, 06:53 AM
 
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Makaster is on a distinguished road
| More
C# Stimulation mouse / keyboard!

Hello!

1. I have problem! How i can stimulate keyboard and mouse on No-Active window?
On active window i use this code:
Code:
// Get a handle to an application window.
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);

// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
&&

Code:
	    IntPtr calculatorHandle = FindWindow(null, "MyGame");

            // Verify that game is a running process.
            if (calculatorHandle == IntPtr.Zero)
            {
                MessageBox.Show("Your game is not running!");
                return;
            }

            // Make game the foreground application and send it 
            // a set of calculations.
            SetForegroundWindow(calculatorHandle);
            System.Threading.Thread.Sleep(500);
            SendKeys.SendWait("Hello!");
            System.Threading.Thread.Sleep(500);
            SendKeys.SendWait(" How are");
            System.Threading.Thread.Sleep(1000);
            SendKeys.SendWait(" You");
            System.Threading.Thread.Sleep(200);
            SendKeys.SendWait("?");
But it works only on the active window. When i minimize game i hear 'Beeps - "its: Wrong song - Error ^^"'

2. How i can stimulate clicked mouse on XYZ position, on Active && no-active window?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with glutKeyboardFunc(keyboard); dathatreya OpenGL Programming 0 04-17-2008 03:25 AM
mouse hovering rahulbaisla MFC Programming 0 03-12-2008 01:28 AM
Label Runtime Scale With Mouse xzyfer C# Programming 1 05-23-2007 09:42 PM
A Microsoft keyboard for the upper crust NewsBot News 0 09-16-2006 09:38 AM



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.