Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Set single key color (Read 3700 times)
Jim
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 1
Joined: May 20th, 2016
Set single key color
May 20th, 2016 at 7:34pm
Print Post  
Is possible to change background (also hover & pressed background too) color of a single key on the keyboard at runtime?

Also, how to lock to capslock on a shift doubleclick/doublepress?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: Set single key color
Reply #1 - May 21st, 2016 at 5:51am
Print Post  
Hi,

At this time painting keys in distinct colors can be done only through a custom KeyTemplate, for example this paints a red Enter key -

Code
Select All
class MyTemplate : KeyTemplate
{
	public MyTemplate()
	{
		defaultBrush = Background;
	}

	GradientBrush defaultBrush;

	public override void Draw(Graphics g, Key key, Mode mode, Font font)
	{
		if (key.Equals(Key.ENTER))
		{
			Background = new GradientBrush(
				new List<Color> { Color.Red },
				new List<float> { 0f }, 0f);
			base.Draw(g, key, mode, font);
			Background = defaultBrush;
			return;
		}

		base.Draw(g, key, mode, font);
	}
}

kb.KeyTemplate = new MyTemplate(); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: Set single key color
Reply #2 - May 21st, 2016 at 6:05am
Print Post  
Quote:
Also, how to lock to capslock on a shift doubleclick/doublepress?


One way I can see to enable CapsLocks is calling Key.CAPSLOCK.Send method. There's no Key-DoubleClicked event available, instead you might hadle KeyPressed and check the time to determine if it's a double click -

Code
Select All
void OnKeyPressed(object sender, VirtualKeyEventArgs e)
{
	if (e.Key.Equals(Key.SHIFT))
	{
		if (lastClick != null &&
			DateTime.Now - lastClick.Value < TimeSpan.FromSeconds(0.5))
		{
			Key.CAPSLOCK.Send(true);
		}

		lastClick = DateTime.Now;
	}
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint