Click here to Skip to main content
15,900,457 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
need to magnify screen when the keyboard cursor moves

currently below code i have tried for mouse pointer.

need magnification when keyboard cursor moves

What I have tried:

Graphics g;
Bitmap bmp;

private void timer1_Tick(object sender, EventArgs e)
{
bmp = new Bitmap(250, 200);
g = this.CreateGraphics();
g = Graphics.FromImage(bmp);

g.CopyFromScreen(MousePosition.X - 100, MousePosition.Y - 10, 0, 0, new Size(300, 300));
pictureBox1.Image = bmp;
}
Posted
Updated 1-Jul-19 1:43am

The first thing to note is that that is bad code: bitmaps and graphics contexts are scarce resources, and you are responsible for disposing of them when you are finished with them. Particularly in the case of Graphics objects.
I'd strongly suggest that you use a using block if you are going to call CreateGraphics:
C#
using (Graphics g = this.CreateGraphics())
   {
   ... use g here ...
   }
... g is automatically discarded here
In fact, you can speed the process up, and get exactly the same results without any bitmaps:
C#
private void T_Tick(object sender, EventArgs e)
    {
    using (Graphics g = myPictureBox.CreateGraphics())
        {
        g.CopyFromScreen(MousePosition.X - 100, MousePosition.Y - 10, 0, 0, new Size(300, 300));
        }
    }

But ... the "keyboard cursor" doesn't exist; the caret that shows when the user can type isn't the same as the mouse cursor - and the most important difference is that there isn't just one for the whole system, every user input control has it's own caret, but only the focussed one is actually displayed.

So to find out when it moved you'd basically have to hook into every single input control in the system, and that's extremely difficult in a managed language like C# (because you don't have direct access to the OS)

I'd suggest that you will have to invest a lot of time into getting that working, and even then ... there will be apps where your code doesn't work because they don't use "standard controls" of any form. So it won;t necessarily be reliable...
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900