C# kısayol tuşları oluşturma

toprak34 (2026) 6 yıl önce sordu

Merhaba;

C# ile bir ekran görüntüsü alma programı yaptım. Herşey güzel ama programı açmadan ve programın içindeki butona tıklamadan ekran görüntüsü almıyor. Buda ekran görüntüsünün bozulmasına sebep oluyor. Yani program ekranın bir kısmını kapladığı için programda açık olarak gözüküyor. Benim istediğim şey şu, programı alta alalım ve program arkada açık iken Prt sc sysrq tuşuna bastığımızda ekran görüntüsünü alıp formdaki picturebox'a aktarsın. Bunu nasıl yapabilirim?
@alattin abi :))

Toplam 2 cevap


alattin (16999) 6 yıl önce cevapladı

Kodların tamamı bana ait değil, ben ekleme ve düzenlemeler yaptım.

Hata yapmaman için Windows Formu içindeki tüm kodları aldım. Form1.cs adı ile uygulamana eklersen sorunsuz çalışır.

 Program CTRL + SHIFT + F12 tuşlarına basıldığında ekran görüntüsü alır
 Ekran görüntüsünü programın olduğu klasöre kaydeder.

C# ile ekran görüntüsü alıp resim olarak kaydetme:

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        //Program CTRL + SHIFT + F12 tuşlarına basıldığında ekran görüntüsü alır
        //Ekran görüntüsünü programın olduğu klasöre kaydeder.
        public Form1()
        {
            InitializeComponent();
            //CTRL+SHIFT için 6  (2+4)
            //Alt = 1, Ctrl = 2, Shift = 4, Win = 8
            RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 6, (int)Keys.F12);
        }
        [DllImport("user32.dll")]
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
        [DllImport("user32.dll")]
        public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
        const int MYACTION_HOTKEY_ID = 1;
        void EkranGoruntusuAl()
        {
            //bitmap oluştur
            var bmpEkranGoruntusu = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                           Screen.PrimaryScreen.Bounds.Height,
                                           PixelFormat.Format32bppArgb);
            // bmpden bir grafik nesnesi yarat
            var gfxEkranGoruntusu = Graphics.FromImage(bmpEkranGoruntusu);

            // Sol ust koseden sag alt koseye kadar ekran goruntusu al
            gfxEkranGoruntusu.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                        Screen.PrimaryScreen.Bounds.Y,
                                        0,
                                        0,
                                        Screen.PrimaryScreen.Bounds.Size,
                                        CopyPixelOperation.SourceCopy);

            // Ekran goruntusunu kaydet(png formatında)
            bmpEkranGoruntusu.Save("EkranGoruntusu.png", ImageFormat.Png);
        }
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0312 && m.WParam.ToInt32() == MYACTION_HOTKEY_ID)
            {
                EkranGoruntusuAl();
            }
            base.WndProc(ref m);
        }

    }
}

 

toprak34 6 yıl önce

@alattin abi kodlar olmadı. İstersen ben direk benim projemin kodlarını vereyim?

toprak34 (2026) 6 yıl önce cevapladı

@alattin projenin kodları,

https://i.hizliresim.com/d7aQyZ.png Ekran görüntüsü.

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;

namespace ekrangoruntusu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap foto = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics grafik = Graphics.FromImage(foto);
            grafik.CopyFromScreen(0, 0, 0, 0, new Size(foto.Width, foto.Height));
            pictureBox1.Image = foto;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "jpeg dosyası(*.jpg)|*.jpg|Bitmap(*.bmp)|*.bmp";

            sfd.Title = "Kayıt";

            sfd.FileName = "resim";

            DialogResult sonuç = sfd.ShowDialog();

            if (sonuç == DialogResult.OK)
            {
                pictureBox1.Image.Save(sfd.FileName);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Y)
            {
                button1.PerformClick();
            }
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            MessageBox.Show("Ekran görüntüsü al butonunal tıklayarak ekran görüntüsü alabilir, kaydet'e tıklayarak ise ekran görüntüsünü masaüstüne kaydedebilirsiniz.", "Kullanım", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void Form1_KeyDown_1(object sender, KeyEventArgs e)
        {

        }
    }
}

(KeyDown özelliği çalışmıyor)