Programing/C#
C# Getting mouse position( timer를 사용하여 X, Y 위치값 얻기 )
꿀주세요
2022. 7. 4. 15:51
타이머는 System.Windows.Forms.Timer 를 사용했습니다.
체크박스에 체크를 하면 timer가 동작되고
스페이스바 키를 눌렀을때
체크박스의 체크가 해제되면서
timer가 정지됩니다.
public partial class Form1 : Form { [DllImport("user32.dll")] static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo); private const uint MOUSEEVENTF_LEFTDOWN = 0x0000; //= 0x0002; // The left button is down. private const uint MOUSEEVENTF_LEFTUP = 0x0000;// = 0x0004; // The left button is up. public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { lbX1.Text = Cursor.Position.X.ToString(); lbY1.Text = Cursor.Position.Y.ToString(); } private void btnStop1_Click(object sender, EventArgs e) { timer1.Stop(); } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { if (cbP1.Checked) { btnStop1.PerformClick(); cbP1.Checked = false; } } } private void cbP1_CheckedChanged(object sender, EventArgs e) { if(cbP1.Checked) { timer1.Start(); this.ActiveControl = null; } } |