🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / not defteri penceresini yakalamak ve sendkeys göndermek

1-) C# RMOS - not defteri penceresini yakalamak ve sendkeys göndermek

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using System.Diagnostics;

using System.Threading;

 

namespace PencereyeSendKeys

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        [DllImport("User32.dll")]

        static extern int SetForegroundWindow(IntPtr point);

 

        private void button1_Click(object sender, EventArgs e)

        {

            Process p = Process.GetProcessesByName("notepad").FirstOrDefault();

            if (p != null) // not defteri açıksa öne getir yaz

            {

                IntPtr h = p.MainWindowHandle;

                SetForegroundWindow(h);

                SendKeys.SendWait("Kod Evreni");

            }

            else // not defteri açık değilse açar ve yazar

            {

                Process islem = Process.Start("notepad.exe");

                islem.WaitForInputIdle();

                IntPtr h = islem.MainWindowHandle;

                SetForegroundWindow(h);

                SendKeys.SendWait("Kod Evreni");

            }

        }

 

        private void button2_Click(object sender, EventArgs e) // ALT+F4 ÇALIŞTIRMAK İÇİN

        {

            Process p = Process.GetProcessesByName("notepad").FirstOrDefault();

            if (p != null)

            {

                IntPtr h = p.MainWindowHandle;

                SetForegroundWindow(h);

                SendKeys.SendWait("%({F4})");

            }

            else

            {

                Process islem = Process.Start("notepad.exe");

                islem.WaitForInputIdle();

                IntPtr h = islem.MainWindowHandle;

                SetForegroundWindow(h);

                Thread.Sleep(2000);

                SendKeys.SendWait("%({F4})");

            }

        }

    }

}

 

 

 

 

 

 

 

2-) .exe penceresini yakalamak ve ÖNE GETİRMEK(ÇOK ÖNEMLİ) bunu kullan

using System;

using System.Linq;

using System.Windows.Forms;

using System.Diagnostics;

 

namespace PencereyeSendKeys

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        const int SW_RESTORE = 9;

 

        [System.Runtime.InteropServices.DllImport("User32.dll")]

        private static extern bool SetForegroundWindow(IntPtr handle);

        [System.Runtime.InteropServices.DllImport("User32.dll")]

        private static extern bool ShowWindow(IntPtr handle, int nCmdShow);

        [System.Runtime.InteropServices.DllImport("User32.dll")]

        private static extern bool IsIconic(IntPtr handle);

 

 

        private void button1_Click(object sender, EventArgs e)

        {

            BringProcessToFront("RM_OCR");// RM_OCR.exe ise RM_OCR gelecek

        }

 

        public void BringProcessToFront(string exeIsmi) // RM_OCR.exe ise RM_OCR gelecek

        {

            try

            {

                Process process = Process.GetProcessesByName(exeIsmi).FirstOrDefault();

                if (process != null) // not defteri açıksa öne getir yaz

                {

                    IntPtr handle = process.MainWindowHandle;

                    if (IsIconic(handle))// pencere arkada bile olsa öne getirir

                    {

                        ShowWindow(handle, SW_RESTORE);

                    }

                    SetForegroundWindow(handle);

 

                    islemYap();

                }

                else // not defteri açık değilse açar ve yazar

                {

                    MessageBox.Show(exeIsmi + ".exe Açık Değil!");

                    /*Process islem = Process.Start("notepad.exe"); // AÇIK DEĞİLSE AÇAR

                    islem.WaitForInputIdle();

                    IntPtr h = islem.MainWindowHandle;

                    SetForegroundWindow(h);

                    SendKeys.SendWait("Kod Evreni");*/

                }

 

            }

            catch (Exception ex)

            {

                MessageBox.Show("HATA! " + ex.Message);

            }

        }

 

        public void islemYap()

        {

            try

            {

                MySendKeys("RAMAZAN");

                MySendKeys("HABER");

                MySendKeys("TUR");

                MySendKeys("M");

                MySendKeys("04.10.1994");

                MySendKeys("123456");

                MySendKeys("01.01.2020");

                MySendKeys("TUR");

                MySendKeys("I");

                MySendKeys("10585701704");

                MySendKeys("EMİNE");

                MySendKeys("NURİ");

                for (int i = 0; i < 12; i++) // 12 tane senkeys yaptıysak 12 tane shift+tab yani imleci başa aldım

                {

                    SendKeys.Send("+{TAB}"); // shift+tab

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show("HATA! " + ex.Message);

            }

        }

 

        public void MySendKeys(string key)

        {

            try

            {

                SendKeys.SendWait("^(a)"); // CTRL+A demek yani bir değer varsa silmesi için

                SendKeys.SendWait(key);

                SendKeys.SendWait("{TAB}");

            }

            catch (Exception ex)

            {

                MessageBox.Show("HATA! " + ex.Message);

            }

        }

    }

}

 

 2021 Ocak 18 Pazartesi
 466