private KeyAssignment get_key(double x, double y, TouchDevice td)
{
y = y - margin_h - 5; if (y < 0) y = 0;
int row = (int)(y / (button_height));// + margin_h));
if (row > rows.Count() - 1) row = rows.Count() - 1;
int sum = rows[row][0];
int col = 0;
while (x > sum)
{
col++;
if (col == rows[row].Count())
col--;
sum = sum + rows[row][col] + margin_w;
}
Rectangle r = new Rectangle();
r.Stroke = new SolidColorBrush(Colors.Black);
r.StrokeThickness = 4;
r.Height = button_height; r.Width = rows[row][col];
Canvas.SetLeft(r, sum - r.Width);
Canvas.SetTop(r, row * (button_height + margin_h));
this.keyboard_canvas.Children.Add(r);
if (!this.rectangles.ContainsKey(td))
this.rectangles.Add(td, r);
else
{
this.keyboard_canvas.Children.Remove(this.rectangles[td]);
this.rectangles.Remove(td);
}
return keys[row][col];
}