rendered paste body//KONSOL EKRANINDA MOUSE KULLANIMI
//Bu Program Hüseyin ÇAKANLI tarafından
//07.02.2012 Tarihinde Konsol örnekleme için yazıldı.
//C# Express ile test edilmiştir.
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class Program
{
//İşletim sistemi çekirdek kütüphanesi GetConsolWindow() adres bilgisi için.
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[StructLayout(LayoutKind.Sequential)]
//Ekran koordinat sınırları yapı tanımı
struct Rect
{
public int Sol, Ust, Sag, Alt;
}
//Handle bilgisi ile aktif ekranın sınır bilgileri alımı
[DllImport("user32.dll")]
static extern bool GetWindowRect(IntPtr handle, out Rect rect);
//Ekranın hafıza işaretçisi
static IntPtr handle;
static Rect rect;
//Fare üzerinde mi? Metodu
static bool isMouseOver()
{
GetWindowRect(handle, out rect);
return (Cursor.Position.X > rect.Sol && Cursor.Position.X < rect.Sag &&
Cursor.Position.Y > rect.Ust && Cursor.Position.Y < rect.Alt);
}
//Ana Program Girişi
static void Main(string[] args)
{
//Pencere Tanımı
Console.WindowWidth = 50;
Console.BufferWidth = 50;
Console.WindowHeight = 20;
//Pencerenin hafıza işaretçisi
handle = GetConsoleWindow();
//Sonsuz Döngü
while (true)
{
Console.Clear();
Console.WriteLine("Fareyi Form icerisinde gezdirin !");
if (isMouseOver())
{
Console.BackgroundColor = ConsoleColor.Yellow;
if (Cursor.Position.X > 0 && Cursor.Position.X < 1000)
{
Console.Clear();
Console.BackgroundColor = ConsoleColor.Blue;
Console.WriteLine("Mouse Koordinatlari==> X:{0},Y:{1}", Cursor.Position.X.ToString(), Cursor.Position.Y.ToString());
}
}
else
Console.BackgroundColor = ConsoleColor.Black;
System.Threading.Thread.Sleep(100);
}
}
}