When my application is opened, initially it can detect whether the numlock is on or off, but after I on or off the numlock when the application is still opened, the numlock status still remain same as the initial one. Here's my code:
bool isNumLockedPressed = System.Windows.Input.Keyboard.IsKeyToggled(System.Windows.Input.Key.NumLock);
public MainWindow()
{
if (isNumLockedPressed == true)
NumLock.Foreground = System.Windows.Media.Brushes.White;
else
NumLock.Foreground = System.Windows.Media.Brushes.Red;
}
I want the numlock status follow with my on/off action. Any suggestions?
UPDATED
This is my modification so far, but still can't get what I want. Any suggestions?
bool isNumLockedPressed = System.Windows.Input.Keyboard.IsKeyToggled(System.Windows.Input.Key.NumLock);
int numLockStatus { get; set; }
public MainWindow()
{
if (isNumLockedPressed == true)
{
numLockStatus = 1;
NumLock.Foreground = System.Windows.Media.Brushes.White;
}
else
{
numLockStatus = 0;
NumLock.Foreground = System.Windows.Media.Brushes.Red;
}
}
private void NumLockKey_Press(object sender, KeyEventArgs e)
{
if (e.Key == Key.NumLock)
{
numLockStatus = 1;
NumLock.Foreground = System.Windows.Media.Brushes.White;
}
else
{
numLockStatus = 0;
NumLock.Foreground = System.Windows.Media.Brushes.Red;
}
}