开发者

How do I get the current screen cursor position?

My objective is to get current position on the screen (out side the form), and save X, Y coords by pres开发者_StackOverflow中文版s "C" for example.

I google and found some suggestion to use api hooks, but i wonder are there a way we can do this task purely in C# code (.NET Lib) ?

Please give me quick sample if possible because im new to c#.

Thanks


Just use:

Cursor.Position

or

Control.MousePosition

To get the position. You can then map the KeyPress event of the form:

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 'c')
        MessageBox.Show(Cursor.Position.ToString());
}

The individual X and Y coordinates are two properties of the Position object.

Documentation: http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜