VirtualKeyboard überarbeitet

This commit is contained in:
Kilian Wirl 2026-05-06 08:45:39 +02:00
parent a78cd3dc32
commit 2b179cd47b
6 changed files with 91 additions and 125 deletions

View File

@ -36,7 +36,7 @@ namespace Deckungsbeitrag.AA_Forms
private void TextBoxText_Click(object sender, EventArgs e) private void TextBoxText_Click(object sender, EventArgs e)
{ {
this.textBoxText.Clear(); this.textBoxText.Clear();
if (Program.istTouch && !Program.hatTastatur) if (Program.istTouch)
{ {
if (keyboard == null || keyboard.IsDisposed) if (keyboard == null || keyboard.IsDisposed)
{ {

View File

@ -508,7 +508,7 @@ namespace Deckungsbeitrag
} }
private void TextBoxKunde_Click(object sender, EventArgs e) private void TextBoxKunde_Click(object sender, EventArgs e)
{ {
if (Program.istTouch && !Program.hatTastatur) if (Program.istTouch)
{ {
if (keyboard == null || keyboard.IsDisposed) if (keyboard == null || keyboard.IsDisposed)
{ {

View File

@ -156,18 +156,18 @@ namespace Deckungsbeitrag
this.textBoxBenutzer.SelectAll(); this.textBoxBenutzer.SelectAll();
if (Program.istTouch && !Program.hatTastatur) if (Program.istTouch)
{ {
if (keyboard == null || keyboard.IsDisposed) if (keyboard == null || keyboard.IsDisposed)
{ {
keyboard = new QwertzKeyboard(textBoxBenutzer, "isAlpha"); keyboard = new QwertzKeyboard(textBoxBenutzer, "isAlpha");
if (keyboard.ShowDialog() == DialogResult.OK) this.ActiveControl.Focus(); keyboard.Show();
} }
else else
{ {
keyboard.Close(); keyboard.Close();
keyboard = new QwertzKeyboard(textBoxBenutzer, "isAlpha"); keyboard = new QwertzKeyboard(textBoxBenutzer, "isAlpha");
if (keyboard.ShowDialog() == DialogResult.OK) this.ActiveControl.Focus(); keyboard.Show();
} }
} }
@ -175,7 +175,9 @@ namespace Deckungsbeitrag
private void TextBoxPasswort_Enter(object sender, EventArgs e) private void TextBoxPasswort_Enter(object sender, EventArgs e)
{ {
if (Program.istTouch && !Program.hatTastatur) this.textBoxPasswort.Focus();
if (Program.istTouch)
{ {
if (keyboard == null || keyboard.IsDisposed) if (keyboard == null || keyboard.IsDisposed)
{ {
@ -198,7 +200,8 @@ namespace Deckungsbeitrag
private void TextBoxPwdWh_Enter(object sender, EventArgs e) private void TextBoxPwdWh_Enter(object sender, EventArgs e)
{ {
if (Program.istTouch && !Program.hatTastatur) this.textBoxPasswort.Focus();
if (Program.istTouch)
{ {
if (keyboard == null || keyboard.IsDisposed) if (keyboard == null || keyboard.IsDisposed)
{ {

View File

@ -45,6 +45,9 @@ namespace Deckungsbeitrag
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
private static extern uint GetRawInputDeviceList(IntPtr pRawInputDeviceList, ref uint puiNumDevices, uint cbSize); private static extern uint GetRawInputDeviceList(IntPtr pRawInputDeviceList, ref uint puiNumDevices, uint cbSize);
[DllImport("user32.dll", SetLastError = true)]
private static extern uint GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
private const int SM_DIGITIZER = 94; private const int SM_DIGITIZER = 94;
private const int SM_MAXIMUMTOUCHES = 95; private const int SM_MAXIMUMTOUCHES = 95;
private const int SM_CONVERTIBLESLATEMODE = 125; private const int SM_CONVERTIBLESLATEMODE = 125;
@ -75,37 +78,7 @@ namespace Deckungsbeitrag
public static bool IsTouchDeviceReady() => HasTouchHardware && IsTouchActive(); public static bool IsTouchDeviceReady() => HasTouchHardware && IsTouchActive();
// Prüft, ob ein Gerät vom Typ "Tastatur" vom System registriert ist
public static bool IsPhysicalKeyboardPresent()
{
uint deviceCount = 0;
uint size = (uint)Marshal.SizeOf(typeof(RAWINPUTDEVICELIST));
if (GetRawInputDeviceList(IntPtr.Zero, ref deviceCount, size) != 0)
return false;
IntPtr pDevices = Marshal.AllocHGlobal((int)(size * deviceCount));
try
{
if (GetRawInputDeviceList(pDevices, ref deviceCount, size) == uint.MaxValue)
return false;
for (int i = 0; i < deviceCount; i++)
{
RAWINPUTDEVICELIST device = (RAWINPUTDEVICELIST)Marshal.PtrToStructure(
new IntPtr(pDevices.ToInt64() + (size * i)), typeof(RAWINPUTDEVICELIST));
if (device.dwType == RIM_TYPEKEYBOARD)
return true;
}
}
finally
{
Marshal.FreeHGlobal(pDevices);
}
return false;
}
private static bool IsRegistryDisabled() private static bool IsRegistryDisabled()
{ {
@ -122,7 +95,7 @@ namespace Deckungsbeitrag
public static string GetStatus() public static string GetStatus()
{ {
return $"Hardware: {HasTouchHardware}, TouchActive: {IsTouchActive()}, Keyboard: {IsPhysicalKeyboardPresent()}, Points: {TouchPoints}, TabletMode: {IsTabletMode}"; return $"Hardware: {HasTouchHardware}, TouchActive: {IsTouchActive()}, Points: {TouchPoints}, TabletMode: {IsTabletMode}";
} }
} }
static class Program static class Program
@ -140,7 +113,6 @@ namespace Deckungsbeitrag
private static readonly string savePath = ConfigurationManager.AppSettings["DateiSavePfad"]; private static readonly string savePath = ConfigurationManager.AppSettings["DateiSavePfad"];
private static readonly bool istest = false; private static readonly bool istest = false;
public static bool istTouch = TouchHelper.IsTouchDeviceReady(); public static bool istTouch = TouchHelper.IsTouchDeviceReady();
public static bool hatTastatur = TouchHelper.IsPhysicalKeyboardPresent();
/// <summary> /// <summary>

View File

@ -71,5 +71,5 @@ Build-Info:
Keine Install-Reminder vorhanden ✅ Keine Install-Reminder vorhanden ✅
Installation: 05.05.2026 13:36 Installation: 05.05.2026 15:38
===================================== =====================================

View File

@ -2,12 +2,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.Diagnostics; using System.Xml.Linq;
namespace VirtualKeyboard namespace VirtualKeyboard
{ {
@ -22,6 +23,10 @@ namespace VirtualKeyboard
// Erweiterte keys auf mehr Buttons (z.B. 14 pro Reihe) // Erweiterte keys auf mehr Buttons (z.B. 14 pro Reihe)
private Button[][] keys = new Button[5][] { private Button[][] keys = new Button[5][] {
new Button[14], new Button[14], new Button[14], new Button[14], new Button[8]}; new Button[14], new Button[14], new Button[14], new Button[14], new Button[8]};
private Button[][] numkeys = new Button[4][] {
new Button[4], new Button[4], new Button[4], new Button[4]};
// **Echtes QWERTZ-Layout** (5 Reihen + Funktion/Steuerung) // **Echtes QWERTZ-Layout** (5 Reihen + Funktion/Steuerung)
private string[] qwertzRows = { private string[] qwertzRows = {
"?1234567890ß⌫↵", // Ziffernreihe "?1234567890ß⌫↵", // Ziffernreihe
@ -52,15 +57,20 @@ namespace VirtualKeyboard
{ {
isNumeric = true; isNumeric = true;
numpadLayout = new string[] { "789", "456", "123", "⌫0↵" }; numpadLayout = new string[] { "789", "456", "123", "⌫0↵" };
InitializeNumPad();
} }
if (numeric == "isCalc") if (numeric == "isCalc")
{ {
isCalc = true; isCalc = true;
numpadLayout = new string[] {"⌫/*-","789+","456","123↵","0,"}; numpadLayout = new string[] {"⌫/*-","789+","456","123↵","0,"};
InitializeNumPad();
} }
if (numeric == "isAlpha") isNumeric = isCalc = false; if (numeric == "isAlpha")
targetTextBox = target; {
InitializeKeyboard(); isNumeric = isCalc = false;
InitializeKeyboard();
}
this.targetTextBox = target;
this.FormBorderStyle = FormBorderStyle.None; this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = Color.FromArgb(1,53,101); this.BackColor = Color.FromArgb(1,53,101);
this.StartPosition = FormStartPosition.Manual; this.StartPosition = FormStartPosition.Manual;
@ -68,7 +78,67 @@ namespace VirtualKeyboard
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
this.targetTextBox.Focus(); this.targetTextBox.Focus();
} }
private void InitializeNumPad()
{
int y = 10, xBase = 10, btnWidth = 70, btnHeight = 55, spacing = 8;
if (isCalc) this.Size = new Size((btnWidth + spacing) * 4 + xBase, (btnHeight + spacing) * 5 + xBase);
if (isNumeric) this.Size = new Size((btnWidth + spacing) * 3 + xBase, (btnHeight + spacing) * 4 + xBase);
for (int row = 0; row < numpadLayout.Length; row++)
{
string rowText = numpadLayout[row];
int rowLength = rowText.Length;
numkeys[row] = new Button[rowLength];
xBase = 10;
for (int col = 0;col < rowLength; col++)
{
char ch = rowText[col];
if (ch == ' ') { xBase += btnWidth + spacing; continue; } // Leerspace für breiten 0
if (ch == '↵')
{
Button okBtn = new Button
{
Text = "OK",
Size = (isCalc) ? new Size(btnWidth, btnHeight * 2 + spacing) : new Size(btnWidth, btnHeight),
Location = new Point(xBase, y),
BackColor = Color.FromArgb(0, 192, 0),
ForeColor = Color.White,
Font = new Font("Arial", 14, FontStyle.Bold),
FlatStyle = FlatStyle.Flat,
Visible = true,
};
okBtn.FlatAppearance.BorderSize = 1;
okBtn.FlatAppearance.BorderColor = Color.Green;
okBtn.Click += OK_Click;
this.Controls.Add(okBtn);
// OK-Button rechts unten (NumPad-Enter-Stil)
continue;
}
if (ch == '+') { btnHeight = btnHeight * 2 + spacing; }
Button btn = new Button
{
Text = ch.ToString(),
Tag = ch,
Size = new Size(btnWidth, btnHeight),
Location = new Point(xBase, y),
Font = new Font("Arial", 18, FontStyle.Bold),
BackColor = Color.FromArgb(240, 240, 240),
FlatStyle = FlatStyle.Flat,
Visible = true,
Enabled = true,
};
btn.Click += Key_Click;
this.Controls.Add(btn);
numkeys[row][col] = btn;
xBase += btn.Width + spacing;
}
y += btnHeight + spacing;
}
}
private void InitializeKeyboard() private void InitializeKeyboard()
{ {
int btnHeight = 60, spacing = 4; int btnHeight = 60, spacing = 4;
@ -146,7 +216,6 @@ namespace VirtualKeyboard
// OK wird in Reihen integriert // OK wird in Reihen integriert
this.Size = new Size((int)(screen.WorkingArea.Width * 0.80), (btnHeight + spacing) * 5 + 10); this.Size = new Size((int)(screen.WorkingArea.Width * 0.80), (btnHeight + spacing) * 5 + 10);
this.MaximumSize = new Size(1000, (btnHeight + spacing) * 5 + 10); this.MaximumSize = new Size(1000, (btnHeight + spacing) * 5 + 10);
UpdateLayout();
} }
private void OK_Click(object sender, EventArgs e) private void OK_Click(object sender, EventArgs e)
@ -156,10 +225,7 @@ namespace VirtualKeyboard
private void Tab_Click(object sender, EventArgs e) private void Tab_Click(object sender, EventArgs e)
{ {
DialogResult result = DialogResult.None; if (targetTextBox.Parent?.SelectNextControl(targetTextBox, true, true, true, true) == true) this.Close();
if (targetTextBox.Parent?.SelectNextControl(targetTextBox, true, true, true, true) == true) result = DialogResult.OK;
else result = DialogResult.Cancel;
this.Close();
} }
private void Key_Click(object sender, EventArgs e) private void Key_Click(object sender, EventArgs e)
@ -191,7 +257,6 @@ namespace VirtualKeyboard
private void ToggleMode_Click() private void ToggleMode_Click()
{ {
isNumeric = !isNumeric; isNumeric = !isNumeric;
UpdateLayout();
} }
private void Shift_Click(object sender, EventArgs e) private void Shift_Click(object sender, EventArgs e)
@ -221,83 +286,9 @@ namespace VirtualKeyboard
} }
} }
} }
else
{
// **VERSTECKE ALLE QWERTZ-Buttons** und zeige nur NumPad
HideAllQwertzButtons();
SetupRealNumPad();
}
this.Refresh(); this.Refresh();
targetTextBox.Focus(); targetTextBox.Focus();
} }
private void HideAllQwertzButtons()
{
// Blende ALLE Keys aus (QWERTZ komplett weg)
foreach (var row in keys)
{
foreach (var btn in row.Where(b => b != null))
{
btn.Visible = false;
}
}
}
private void SetupRealNumPad()
{
int y = 10, xBase = 10, btnWidth = 70, btnHeight = 55, spacing = 8;
if (isCalc) this.Size = new Size((btnWidth + spacing) * 4 + xBase, (btnHeight + spacing) * 5 + xBase);
if (isNumeric) this.Size = new Size((btnWidth + spacing) * 3 + xBase, (btnHeight + spacing) * 4 + xBase);
// NumPad-Grids füllen (erste 4 Reihen)
for (int row = 0; row < numpadLayout.Length; row++)
{
string rowText = numpadLayout[row];
btnHeight = 55;
xBase = 10;
for (int col = 0; col < rowText.Length; col++)
{
char ch = rowText[col];
if (ch == ' ') { xBase += btnWidth + spacing; continue; } // Leerspace für breiten 0
if (ch == '↵')
{
Button okBtn = keys[row][col];
// OK-Button rechts unten (NumPad-Enter-Stil)
okBtn.Text = "OK";
okBtn.Size = (isCalc) ? new Size(btnWidth, btnHeight * 2 + spacing) : new Size(btnWidth, btnHeight);
okBtn.Location = new Point(xBase, y);
okBtn.BackColor = Color.FromArgb(0, 192, 0);
okBtn.ForeColor = Color.White;
okBtn.Font = new Font("Arial", 14, FontStyle.Bold);
okBtn.FlatStyle = FlatStyle.Flat;
okBtn.FlatAppearance.BorderSize = 1;
okBtn.FlatAppearance.BorderColor = Color.Green;
okBtn.Visible = true;
okBtn.Click += OK_Click;
continue;
}
if (ch == '+') { btnHeight = btnHeight * 2 + spacing; }
Button btn = keys[row][col];
btn.Text = ch.ToString();
btn.Tag = ch;
btn.Size = (row == 4 && col == 0) ? new Size(btnWidth * 2 + spacing, btnHeight) : new Size(btnWidth, btnHeight); // Breiter 0
btn.Location = new Point(xBase, y);
btn.Font = new Font("Arial", 18, FontStyle.Bold);
btn.BackColor = Color.FromArgb(240, 240, 240); // NumPad-Look
btn.FlatStyle = FlatStyle.Flat;
btn.FlatAppearance.BorderSize = 1;
btn.Visible = true;
btn.Enabled = true;
xBase += btn.Width + spacing;
}
y += (btnHeight > 55) ? (btnHeight / 2) + (spacing / 2) : btnHeight + spacing;
}
// Verstecke ungenutzte Keys (Reihen 4+)
for (int row = 5; row < keys.Length; row++)
for (int col = 0; col < keys[row].Length; col++)
keys[row][col].Visible = false;
}
protected override void OnShown(EventArgs e) protected override void OnShown(EventArgs e)
{ {