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. C#
  4. How to make an inactive window work and respond to buttons (C# .NET windows forms)

How to make an inactive window work and respond to buttons (C# .NET windows forms)

Scheduled Pinned Locked Moved C#
csharptutorialwinformslinqgraphics
2 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.
  • M Offline
    M Offline
    Marcin Rajczakowski
    wrote on last edited by
    #1

    I have such a clicker, I want to be able to continue, for example, after opening another application, or vice versa. Please help All code here:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace Klikacz____TzPw
    {

    public partial class Form1 : Form
    {
        \[DllImport(dllName: "User32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)\]
    
        public static extern void mouse\_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
    
        private const int LEFTUP = 0x0004;
        private const int LEFTDOWN = 0x0002;
    
        public Form1()
        {
            InitializeComponent();
            this.ActiveControl = button1;
            button1.Focus();
        }
    
        private void Click\_clock\_Tick(object sender, EventArgs e)
        {
            Random rnd = new Random();
            int maxcps = (int)Math.Round(1000.0 / (trackBar1.Value + 0 \* 0.2));
            int mincps = (int)Math.Round(1000.0 / (trackBar1.Value + 0 \* 0.4));
    
            try
            {
                Click\_clock.Interval = rnd.Next(mincps, maxcps);
            }
    
            catch
            {
                //Ignored..
            }
    
            bool mousdown = MouseButtons == MouseButtons.Left;
            if (mousdown)
            {
                mouse\_event(dwFlags: LEFTUP, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0);
                Thread.Sleep(millisecondsTimeout: rnd.Next(1, 6));
                mouse\_event(dwFlags: LEFTDOWN, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0);
            }
    
        }
    
        private void button1\_Click(object sender, EventArgs e)
        {
            if (button1.Text.Contains("Uruchom"))
            {
                Click\_clock.Start();
                button1.Text = "Wstrzymaj";
            }
            else
            {
                Click\_clock.Stop();
                button1.Text = "Uruchom";
            }
        }
    
        private void trackBar1\_Scroll(object sender, EventArgs e)
        {
            CPSValue.Text = "CPS = " + trackBar1.Value.ToString();
        }
    }
    

    }

    B 1 Reply Last reply
    0
    • M Marcin Rajczakowski

      I have such a clicker, I want to be able to continue, for example, after opening another application, or vice versa. Please help All code here:

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Diagnostics;
      using System.Drawing;
      using System.Linq;
      using System.Runtime.InteropServices;
      using System.Text;
      using System.Threading;
      using System.Threading.Tasks;
      using System.Windows.Forms;

      namespace Klikacz____TzPw
      {

      public partial class Form1 : Form
      {
          \[DllImport(dllName: "User32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)\]
      
          public static extern void mouse\_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
      
          private const int LEFTUP = 0x0004;
          private const int LEFTDOWN = 0x0002;
      
          public Form1()
          {
              InitializeComponent();
              this.ActiveControl = button1;
              button1.Focus();
          }
      
          private void Click\_clock\_Tick(object sender, EventArgs e)
          {
              Random rnd = new Random();
              int maxcps = (int)Math.Round(1000.0 / (trackBar1.Value + 0 \* 0.2));
              int mincps = (int)Math.Round(1000.0 / (trackBar1.Value + 0 \* 0.4));
      
              try
              {
                  Click\_clock.Interval = rnd.Next(mincps, maxcps);
              }
      
              catch
              {
                  //Ignored..
              }
      
              bool mousdown = MouseButtons == MouseButtons.Left;
              if (mousdown)
              {
                  mouse\_event(dwFlags: LEFTUP, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0);
                  Thread.Sleep(millisecondsTimeout: rnd.Next(1, 6));
                  mouse\_event(dwFlags: LEFTDOWN, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0);
              }
      
          }
      
          private void button1\_Click(object sender, EventArgs e)
          {
              if (button1.Text.Contains("Uruchom"))
              {
                  Click\_clock.Start();
                  button1.Text = "Wstrzymaj";
              }
              else
              {
                  Click\_clock.Stop();
                  button1.Text = "Uruchom";
              }
          }
      
          private void trackBar1\_Scroll(object sender, EventArgs e)
          {
              CPSValue.Text = "CPS = " + trackBar1.Value.ToString();
          }
      }
      

      }

      B Offline
      B Offline
      BillWoodruff
      wrote on last edited by
      #2
      1. you can keep things in your app running, whether or not your app is the current active application, by using a Timer, or having a some form of 'while loop. advice : don't use a 'while loop. 2) when your app is not active ... it can still get messages by using a GlobalKeyBoardHook it defines, and registers, that intercepts some keyboard combination of keys. warning: you override some other app's keyboard hooks, and you are in trouble. I believe what you probably need to use is the SystemTray app model, and CP has several articles that will show you how to use that: [^] However, if what you want is some kind of stealth monitoring app: you won't get help with that here.

      «The mind is not a vessel to be filled but a fire to be kindled» Plutarch

      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