Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. How to control another application

How to control another application

Scheduled Pinned Locked Moved Design and Architecture
csharpasp-nethelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cullyk
    wrote on last edited by
    #1

    I am an ASP.NET web dev but I am trying to build myself a little desktop application that takes control of another application for me. What I want it to do is pretty simple, type some text into a textbox on another application then click a few buttons for me. Problem is I don't even know where to start or what language would be best to write this in? Can anyone point me in the right direction. I can give more information for anyone who is interested Thanks, Colum

    L 1 Reply Last reply
    0
    • C cullyk

      I am an ASP.NET web dev but I am trying to build myself a little desktop application that takes control of another application for me. What I want it to do is pretty simple, type some text into a textbox on another application then click a few buttons for me. Problem is I don't even know where to start or what language would be best to write this in? Can anyone point me in the right direction. I can give more information for anyone who is interested Thanks, Colum

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I would do such things (and most others) in C#. For keyboard input, .NET has a SendKeys class. For mouse input, you would need P/Invoke to call native code in Windows DLL libraries, such as

      	\[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall, SetLastError=true)\]
      	public static extern IntPtr SendInput(int count, ref INPUT input, int size);
      
      	\[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall, SetLastError=true)\]
      	public static extern IntPtr SendInput(int count, ref INPUT2 input, int size);
      
      	\[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)\]
      	public static extern IntPtr SetCursorPos(int x, int y);
      
      	public struct MOUSEINPUT {
      		public int dx;
      		public int dy;
      		public int mouseData;
      		public int dwFlags;
      		public int time;
      		public IntPtr dwExtraInfo;
      	}
      
      	public struct INPUT {
      		public uint type;
      		public MOUSEINPUT mi;
      	}
      
      	public struct INPUT2 {
      		public uint type1;
      		public MOUSEINPUT mi1;
      		public uint type2;
      		public MOUSEINPUT mi2;
      	}
      

      Now most of this is considered a hack as you can't do it reliably: it suffices for another application, window or control to suddenly get focus or being shown on the display, for your keys and/or mouse clicks to be intercepted by them (and maybe causing havoc). The better way is to use application interfaces, if they exist. Example: there are "Primary Interop Assemblies" for controlling Office from .NET :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      C 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I would do such things (and most others) in C#. For keyboard input, .NET has a SendKeys class. For mouse input, you would need P/Invoke to call native code in Windows DLL libraries, such as

        	\[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall, SetLastError=true)\]
        	public static extern IntPtr SendInput(int count, ref INPUT input, int size);
        
        	\[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall, SetLastError=true)\]
        	public static extern IntPtr SendInput(int count, ref INPUT2 input, int size);
        
        	\[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)\]
        	public static extern IntPtr SetCursorPos(int x, int y);
        
        	public struct MOUSEINPUT {
        		public int dx;
        		public int dy;
        		public int mouseData;
        		public int dwFlags;
        		public int time;
        		public IntPtr dwExtraInfo;
        	}
        
        	public struct INPUT {
        		public uint type;
        		public MOUSEINPUT mi;
        	}
        
        	public struct INPUT2 {
        		public uint type1;
        		public MOUSEINPUT mi1;
        		public uint type2;
        		public MOUSEINPUT mi2;
        	}
        

        Now most of this is considered a hack as you can't do it reliably: it suffices for another application, window or control to suddenly get focus or being shown on the display, for your keys and/or mouse clicks to be intercepted by them (and maybe causing havoc). The better way is to use application interfaces, if they exist. Example: there are "Primary Interop Assemblies" for controlling Office from .NET :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        C Offline
        C Offline
        cullyk
        wrote on last edited by
        #3

        This is great thank you, I'll have a go at this, the application is for personal use so it being a hack is fine. Basically I am an online poker player and there is a guy who is VERY bad. So I plan to keep pressing the search button until he sits down and then have the application very quickly sit me in the best seat available before all the others players get in there. There are alot of commercial applications that do very similar things but for the life of me I didnt know where to start. Thanks, Colum

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups