Mouse lag with touch screen connected, almost no lag without
up vote
0
down vote
favorite
I have a touch screen (LG 23ET83V if it matters) and I wanted to write an extremely basic paint application for my 3 year-old daughter: no extensive tool palettes with luxury tools she doesn't care about (I didn't like Tuxpaint for that matter). Just plain painting. So much for my motivation.
But with the code below I observe the following odd behavior:
On the target machine (Windows 10 Pro, 6 core AMD from 2014 or so) when painting with my finger there is a small lag (~0.5 seconds?) of the painting behind the position of my finger. Only after I rest my finger, the drawing position catches up with the position of my finger.
When I draw with the mouse, the lag gets impressive (~ 2-4 seconds!) for longer movements. If I stop mouse movement, the drawing position eventually catches up. It doesn't terribly look like the mouse is generating a higher rate of MOUSE_MOVE events than the touch controller did while moving my finger in bullet 1.
When I disconnect the USB cable of the touch controller of the screen, the mouse lag almost vanishes. Well it is still noticeable but acceptable (say ~0.25s)
When I draw with the mouse on the development machine (Intel Q6600 quad core from ~2008 or so), I see no mouse lag whatsoever.
If it is hardware or driver related I am probably out of luck. But it somehow looks to me as if Windows is trying to smooth touch movements by averaging several consecutive mouse positions. If this is true, can I control the averaging? Any other ideas as to the cause of the problem?
PS: when I use MS Paint on the machine that shows the above problem, I can see no lag at all. So the problem must be caused by something that is either C# related or related to the specific way I use the API.
public partial class MainWindow : Window
{
WriteableBitmap bitmap;
public MainWindow()
{
InitializeComponent();
// create bitmap the size of whole screen
int bitmapWidth = Convert.ToInt32(SystemParameters.PrimaryScreenWidth);
int bitmapHeight = Convert.ToInt32(SystemParameters.PrimaryScreenHeight);
bitmap = new WriteableBitmap(bitmapWidth, bitmapHeight, 96, 96, PixelFormats.Bgra32, null);
canvasImage.Source = bitmap;
}
void plot(int x, int y, uint value)
{
// just draw one pixel for barebones testing
uint valueArray = new uint[1];
valueArray[0] = value;
bitmap.WritePixels(new Int32Rect(0, 0, 1, 1), valueArray, 4, x, y);
}
Point previousPosition;
void imageMouseMove(object sender, MouseEventArgs e)
{
Point currentPosition = e.GetPosition(canvasImage);
if (e.LeftButton == MouseButtonState.Pressed)
{
int x2 = (int)Math.Floor(currentPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y2 = (int)Math.Floor(currentPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
int x1 = (int)Math.Floor(previousPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y1 = (int)Math.Floor(previousPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
plot(x2,y2, 0xFF800000);
}
previousPosition = currentPosition;
}
void button1_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
Markup:
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="Paintuition.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Paintuition"
ResizeMode="NoResize"
WindowState="Maximized"
WindowStyle="None">
<Grid>
<Image
x:Name="canvasImage"
MouseMove="imageMouseMove" />
<Button
Content="X"
x:Name="button1"
Click="button1_Click"
Background="Red"
BorderBrush="#FFFFBFBF"
FontFamily="Arial"
Foreground="White"
FontWeight="ExtraBold"
FontSize="54"
Width="66"
Height="65"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,42,34,0" />
</Grid>
</Window>
c# wpf windows-10 touch
add a comment |
up vote
0
down vote
favorite
I have a touch screen (LG 23ET83V if it matters) and I wanted to write an extremely basic paint application for my 3 year-old daughter: no extensive tool palettes with luxury tools she doesn't care about (I didn't like Tuxpaint for that matter). Just plain painting. So much for my motivation.
But with the code below I observe the following odd behavior:
On the target machine (Windows 10 Pro, 6 core AMD from 2014 or so) when painting with my finger there is a small lag (~0.5 seconds?) of the painting behind the position of my finger. Only after I rest my finger, the drawing position catches up with the position of my finger.
When I draw with the mouse, the lag gets impressive (~ 2-4 seconds!) for longer movements. If I stop mouse movement, the drawing position eventually catches up. It doesn't terribly look like the mouse is generating a higher rate of MOUSE_MOVE events than the touch controller did while moving my finger in bullet 1.
When I disconnect the USB cable of the touch controller of the screen, the mouse lag almost vanishes. Well it is still noticeable but acceptable (say ~0.25s)
When I draw with the mouse on the development machine (Intel Q6600 quad core from ~2008 or so), I see no mouse lag whatsoever.
If it is hardware or driver related I am probably out of luck. But it somehow looks to me as if Windows is trying to smooth touch movements by averaging several consecutive mouse positions. If this is true, can I control the averaging? Any other ideas as to the cause of the problem?
PS: when I use MS Paint on the machine that shows the above problem, I can see no lag at all. So the problem must be caused by something that is either C# related or related to the specific way I use the API.
public partial class MainWindow : Window
{
WriteableBitmap bitmap;
public MainWindow()
{
InitializeComponent();
// create bitmap the size of whole screen
int bitmapWidth = Convert.ToInt32(SystemParameters.PrimaryScreenWidth);
int bitmapHeight = Convert.ToInt32(SystemParameters.PrimaryScreenHeight);
bitmap = new WriteableBitmap(bitmapWidth, bitmapHeight, 96, 96, PixelFormats.Bgra32, null);
canvasImage.Source = bitmap;
}
void plot(int x, int y, uint value)
{
// just draw one pixel for barebones testing
uint valueArray = new uint[1];
valueArray[0] = value;
bitmap.WritePixels(new Int32Rect(0, 0, 1, 1), valueArray, 4, x, y);
}
Point previousPosition;
void imageMouseMove(object sender, MouseEventArgs e)
{
Point currentPosition = e.GetPosition(canvasImage);
if (e.LeftButton == MouseButtonState.Pressed)
{
int x2 = (int)Math.Floor(currentPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y2 = (int)Math.Floor(currentPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
int x1 = (int)Math.Floor(previousPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y1 = (int)Math.Floor(previousPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
plot(x2,y2, 0xFF800000);
}
previousPosition = currentPosition;
}
void button1_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
Markup:
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="Paintuition.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Paintuition"
ResizeMode="NoResize"
WindowState="Maximized"
WindowStyle="None">
<Grid>
<Image
x:Name="canvasImage"
MouseMove="imageMouseMove" />
<Button
Content="X"
x:Name="button1"
Click="button1_Click"
Background="Red"
BorderBrush="#FFFFBFBF"
FontFamily="Arial"
Foreground="White"
FontWeight="ExtraBold"
FontSize="54"
Width="66"
Height="65"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,42,34,0" />
</Grid>
</Window>
c# wpf windows-10 touch
Try the InvCanvas control.
– Clemens
yesterday
Thanks Clemens, I will definitely try that in the end. My plan is also to support multi touch painting. However I also would like to understand what's the problem with my current approach.
– oliver
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a touch screen (LG 23ET83V if it matters) and I wanted to write an extremely basic paint application for my 3 year-old daughter: no extensive tool palettes with luxury tools she doesn't care about (I didn't like Tuxpaint for that matter). Just plain painting. So much for my motivation.
But with the code below I observe the following odd behavior:
On the target machine (Windows 10 Pro, 6 core AMD from 2014 or so) when painting with my finger there is a small lag (~0.5 seconds?) of the painting behind the position of my finger. Only after I rest my finger, the drawing position catches up with the position of my finger.
When I draw with the mouse, the lag gets impressive (~ 2-4 seconds!) for longer movements. If I stop mouse movement, the drawing position eventually catches up. It doesn't terribly look like the mouse is generating a higher rate of MOUSE_MOVE events than the touch controller did while moving my finger in bullet 1.
When I disconnect the USB cable of the touch controller of the screen, the mouse lag almost vanishes. Well it is still noticeable but acceptable (say ~0.25s)
When I draw with the mouse on the development machine (Intel Q6600 quad core from ~2008 or so), I see no mouse lag whatsoever.
If it is hardware or driver related I am probably out of luck. But it somehow looks to me as if Windows is trying to smooth touch movements by averaging several consecutive mouse positions. If this is true, can I control the averaging? Any other ideas as to the cause of the problem?
PS: when I use MS Paint on the machine that shows the above problem, I can see no lag at all. So the problem must be caused by something that is either C# related or related to the specific way I use the API.
public partial class MainWindow : Window
{
WriteableBitmap bitmap;
public MainWindow()
{
InitializeComponent();
// create bitmap the size of whole screen
int bitmapWidth = Convert.ToInt32(SystemParameters.PrimaryScreenWidth);
int bitmapHeight = Convert.ToInt32(SystemParameters.PrimaryScreenHeight);
bitmap = new WriteableBitmap(bitmapWidth, bitmapHeight, 96, 96, PixelFormats.Bgra32, null);
canvasImage.Source = bitmap;
}
void plot(int x, int y, uint value)
{
// just draw one pixel for barebones testing
uint valueArray = new uint[1];
valueArray[0] = value;
bitmap.WritePixels(new Int32Rect(0, 0, 1, 1), valueArray, 4, x, y);
}
Point previousPosition;
void imageMouseMove(object sender, MouseEventArgs e)
{
Point currentPosition = e.GetPosition(canvasImage);
if (e.LeftButton == MouseButtonState.Pressed)
{
int x2 = (int)Math.Floor(currentPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y2 = (int)Math.Floor(currentPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
int x1 = (int)Math.Floor(previousPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y1 = (int)Math.Floor(previousPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
plot(x2,y2, 0xFF800000);
}
previousPosition = currentPosition;
}
void button1_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
Markup:
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="Paintuition.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Paintuition"
ResizeMode="NoResize"
WindowState="Maximized"
WindowStyle="None">
<Grid>
<Image
x:Name="canvasImage"
MouseMove="imageMouseMove" />
<Button
Content="X"
x:Name="button1"
Click="button1_Click"
Background="Red"
BorderBrush="#FFFFBFBF"
FontFamily="Arial"
Foreground="White"
FontWeight="ExtraBold"
FontSize="54"
Width="66"
Height="65"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,42,34,0" />
</Grid>
</Window>
c# wpf windows-10 touch
I have a touch screen (LG 23ET83V if it matters) and I wanted to write an extremely basic paint application for my 3 year-old daughter: no extensive tool palettes with luxury tools she doesn't care about (I didn't like Tuxpaint for that matter). Just plain painting. So much for my motivation.
But with the code below I observe the following odd behavior:
On the target machine (Windows 10 Pro, 6 core AMD from 2014 or so) when painting with my finger there is a small lag (~0.5 seconds?) of the painting behind the position of my finger. Only after I rest my finger, the drawing position catches up with the position of my finger.
When I draw with the mouse, the lag gets impressive (~ 2-4 seconds!) for longer movements. If I stop mouse movement, the drawing position eventually catches up. It doesn't terribly look like the mouse is generating a higher rate of MOUSE_MOVE events than the touch controller did while moving my finger in bullet 1.
When I disconnect the USB cable of the touch controller of the screen, the mouse lag almost vanishes. Well it is still noticeable but acceptable (say ~0.25s)
When I draw with the mouse on the development machine (Intel Q6600 quad core from ~2008 or so), I see no mouse lag whatsoever.
If it is hardware or driver related I am probably out of luck. But it somehow looks to me as if Windows is trying to smooth touch movements by averaging several consecutive mouse positions. If this is true, can I control the averaging? Any other ideas as to the cause of the problem?
PS: when I use MS Paint on the machine that shows the above problem, I can see no lag at all. So the problem must be caused by something that is either C# related or related to the specific way I use the API.
public partial class MainWindow : Window
{
WriteableBitmap bitmap;
public MainWindow()
{
InitializeComponent();
// create bitmap the size of whole screen
int bitmapWidth = Convert.ToInt32(SystemParameters.PrimaryScreenWidth);
int bitmapHeight = Convert.ToInt32(SystemParameters.PrimaryScreenHeight);
bitmap = new WriteableBitmap(bitmapWidth, bitmapHeight, 96, 96, PixelFormats.Bgra32, null);
canvasImage.Source = bitmap;
}
void plot(int x, int y, uint value)
{
// just draw one pixel for barebones testing
uint valueArray = new uint[1];
valueArray[0] = value;
bitmap.WritePixels(new Int32Rect(0, 0, 1, 1), valueArray, 4, x, y);
}
Point previousPosition;
void imageMouseMove(object sender, MouseEventArgs e)
{
Point currentPosition = e.GetPosition(canvasImage);
if (e.LeftButton == MouseButtonState.Pressed)
{
int x2 = (int)Math.Floor(currentPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y2 = (int)Math.Floor(currentPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
int x1 = (int)Math.Floor(previousPosition.X * canvasImage.Source.Width / canvasImage.ActualWidth);
int y1 = (int)Math.Floor(previousPosition.Y * canvasImage.Source.Height / canvasImage.ActualHeight);
plot(x2,y2, 0xFF800000);
}
previousPosition = currentPosition;
}
void button1_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
Markup:
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="Paintuition.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Paintuition"
ResizeMode="NoResize"
WindowState="Maximized"
WindowStyle="None">
<Grid>
<Image
x:Name="canvasImage"
MouseMove="imageMouseMove" />
<Button
Content="X"
x:Name="button1"
Click="button1_Click"
Background="Red"
BorderBrush="#FFFFBFBF"
FontFamily="Arial"
Foreground="White"
FontWeight="ExtraBold"
FontSize="54"
Width="66"
Height="65"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,42,34,0" />
</Grid>
</Window>
c# wpf windows-10 touch
c# wpf windows-10 touch
edited 14 hours ago
asked yesterday
oliver
1,376621
1,376621
Try the InvCanvas control.
– Clemens
yesterday
Thanks Clemens, I will definitely try that in the end. My plan is also to support multi touch painting. However I also would like to understand what's the problem with my current approach.
– oliver
yesterday
add a comment |
Try the InvCanvas control.
– Clemens
yesterday
Thanks Clemens, I will definitely try that in the end. My plan is also to support multi touch painting. However I also would like to understand what's the problem with my current approach.
– oliver
yesterday
Try the InvCanvas control.
– Clemens
yesterday
Try the InvCanvas control.
– Clemens
yesterday
Thanks Clemens, I will definitely try that in the end. My plan is also to support multi touch painting. However I also would like to understand what's the problem with my current approach.
– oliver
yesterday
Thanks Clemens, I will definitely try that in the end. My plan is also to support multi touch painting. However I also would like to understand what's the problem with my current approach.
– oliver
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Too bad nobody's got an idea about the cause of this problem. Although I don't have a real solution, I have used the following workaround (for the benefit of anyone wanting to do the same as me, ie. drawing for little children):
I have resorted to Gimp now, which allows a lot of more or less child friendly customizations:
- the main toolbox can be made to hide all tools but brush and eraser
- the "color" dockable toolbar set to the color wheel is quite child friendly, otherwise with the same toolbar a custom created palette with some rainbow colors can be accessed, being even more child friendly; resize the floating toolbar to a reasonable size
- the only other toolbar I use is the brushes toolbar, where I remove all but the most basic circular gaussian brushes (strangely the other brushes can only be removed in the file system)
- start the application in full screen mode
Unfortunately, even in this simple setup there are still several handles/menus/gestures that give unintended effects for shaky children's fingers, for example undocking/moving a toolbar, swapping foreground/background color etc.. But it is at least as close to a little child's drawing program as it can get.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Too bad nobody's got an idea about the cause of this problem. Although I don't have a real solution, I have used the following workaround (for the benefit of anyone wanting to do the same as me, ie. drawing for little children):
I have resorted to Gimp now, which allows a lot of more or less child friendly customizations:
- the main toolbox can be made to hide all tools but brush and eraser
- the "color" dockable toolbar set to the color wheel is quite child friendly, otherwise with the same toolbar a custom created palette with some rainbow colors can be accessed, being even more child friendly; resize the floating toolbar to a reasonable size
- the only other toolbar I use is the brushes toolbar, where I remove all but the most basic circular gaussian brushes (strangely the other brushes can only be removed in the file system)
- start the application in full screen mode
Unfortunately, even in this simple setup there are still several handles/menus/gestures that give unintended effects for shaky children's fingers, for example undocking/moving a toolbar, swapping foreground/background color etc.. But it is at least as close to a little child's drawing program as it can get.
add a comment |
up vote
0
down vote
Too bad nobody's got an idea about the cause of this problem. Although I don't have a real solution, I have used the following workaround (for the benefit of anyone wanting to do the same as me, ie. drawing for little children):
I have resorted to Gimp now, which allows a lot of more or less child friendly customizations:
- the main toolbox can be made to hide all tools but brush and eraser
- the "color" dockable toolbar set to the color wheel is quite child friendly, otherwise with the same toolbar a custom created palette with some rainbow colors can be accessed, being even more child friendly; resize the floating toolbar to a reasonable size
- the only other toolbar I use is the brushes toolbar, where I remove all but the most basic circular gaussian brushes (strangely the other brushes can only be removed in the file system)
- start the application in full screen mode
Unfortunately, even in this simple setup there are still several handles/menus/gestures that give unintended effects for shaky children's fingers, for example undocking/moving a toolbar, swapping foreground/background color etc.. But it is at least as close to a little child's drawing program as it can get.
add a comment |
up vote
0
down vote
up vote
0
down vote
Too bad nobody's got an idea about the cause of this problem. Although I don't have a real solution, I have used the following workaround (for the benefit of anyone wanting to do the same as me, ie. drawing for little children):
I have resorted to Gimp now, which allows a lot of more or less child friendly customizations:
- the main toolbox can be made to hide all tools but brush and eraser
- the "color" dockable toolbar set to the color wheel is quite child friendly, otherwise with the same toolbar a custom created palette with some rainbow colors can be accessed, being even more child friendly; resize the floating toolbar to a reasonable size
- the only other toolbar I use is the brushes toolbar, where I remove all but the most basic circular gaussian brushes (strangely the other brushes can only be removed in the file system)
- start the application in full screen mode
Unfortunately, even in this simple setup there are still several handles/menus/gestures that give unintended effects for shaky children's fingers, for example undocking/moving a toolbar, swapping foreground/background color etc.. But it is at least as close to a little child's drawing program as it can get.
Too bad nobody's got an idea about the cause of this problem. Although I don't have a real solution, I have used the following workaround (for the benefit of anyone wanting to do the same as me, ie. drawing for little children):
I have resorted to Gimp now, which allows a lot of more or less child friendly customizations:
- the main toolbox can be made to hide all tools but brush and eraser
- the "color" dockable toolbar set to the color wheel is quite child friendly, otherwise with the same toolbar a custom created palette with some rainbow colors can be accessed, being even more child friendly; resize the floating toolbar to a reasonable size
- the only other toolbar I use is the brushes toolbar, where I remove all but the most basic circular gaussian brushes (strangely the other brushes can only be removed in the file system)
- start the application in full screen mode
Unfortunately, even in this simple setup there are still several handles/menus/gestures that give unintended effects for shaky children's fingers, for example undocking/moving a toolbar, swapping foreground/background color etc.. But it is at least as close to a little child's drawing program as it can get.
answered 9 hours ago
oliver
1,376621
1,376621
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349275%2fmouse-lag-with-touch-screen-connected-almost-no-lag-without%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try the InvCanvas control.
– Clemens
yesterday
Thanks Clemens, I will definitely try that in the end. My plan is also to support multi touch painting. However I also would like to understand what's the problem with my current approach.
– oliver
yesterday