I’m inviting you to take a part in testing of “Keys Notificator”.
This is small and useful program for keyboard monitoring that can be used to monitor common keys as [Shift], [Ctrl], [Alt], [Caps Lock], [Scroll Lock] and [Num Lock]. Very useful to alert users about change in keyboard layout like language ([Alt] + [Shift] ENG <=> HEB) or capital letters.
The “Keys Notificator” is an open-source project and is a part of my community contribution under GNU General Public License. The published/released version is “Beta” version that will be improved and extended in future. Any .NET developer can take a part in project development.
The application binaries (EXE) can be downloaded from here
.
The project source code can be downloaded from here
.
(I’m planning to write detailed and more technological post about the project in near future)
Thanks :)
PS
I’m not responsible for any damage that may be caused by using this post or its content. Any materials in this post were provided AS IS without any changes and other meanings.
Recently I’ve required to add Mouse-Wheel support in some of our Silverlight projects. Quickly discovered that unfortunately this feature isn’t supported in built-in events of Silverlight (at least in versions 1.0 and 2.0). After short search I found this post with sample code that solves this problem by attaching handlers to mouse events on html page.
I made some changes in “MouseWheelHelper” class and added “UIElementExtender” class that extends classes that derived from “UIElement” class in order to provide Mouse-Wheel support.
Here small example that uses “MouseWheelHelper” and “UIElementExtender”:
(use mouse wheel to zoom-in/out, also you can change image by pasting new url into texbox)
Some code samples:
Attach even handler “HandleMouseWheel” to event from HTML-Side (each web-browser has different event for mouse-wheel):
if (HtmlPage.BrowserInformation.UserAgent.Contains("Chrome"))
HtmlPage.Window.AttachEvent("onmousewheel", HandleMouseWheel);
else if (HtmlPage.BrowserInformation.UserAgent.Contains("Firefox"))
HtmlPage.Window.AttachEvent("DOMMouseScroll", HandleMouseWheel);
else
HtmlPage.Document.AttachEvent("onmousewheel", HandleMouseWheel);
“HandleMouseWheel” event handler (each web-browser has specific property for mouse-wheel-delta, method corrects some values):
private void HandleMouseWheel(object sender, HtmlEventArgs args)
{
double delta = 0;
ScriptObject eventObj = args.EventObject;
if (eventObj.GetProperty("wheelDelta") != null)
{
delta = ((double) eventObj.GetProperty("wheelDelta"));
if (HtmlPage.Window.GetProperty("opera") != null)
delta = -delta;
else if (HtmlPage.BrowserInformation.UserAgent.Contains("Chrome"))
delta /= 140;
else
delta /= 120;
}
else if (eventObj.GetProperty("detail") != null)
{
delta = -((double) eventObj.GetProperty("detail"));
if (!HtmlPage.BrowserInformation.UserAgent.Contains("Macintosh"))
delta /= 2;
}
if (delta == 0 || Moved == null) return;
var wheelArgs = new MouseWheelEventArgs(delta);
if (Moved != null) Moved(this, wheelArgs);
if (wheelArgs.Handled) args.PreventDefault();
}
Method-Extension for “UIElement”:
public static void RegisterMouseWheelHandler(this UIElement sender, EventHandler<MouseWheelEventArgs> handler){ /*...*/ }
Use of Method-Extension:
this.RegisterMouseWheelHandler(OnMouseWheel);
/* ... */
// "MouseWheel" event handler, controls "zoom" of Image control
private void OnMouseWheel(object sender, MouseWheelEventArgs e)
{
if (e == null) return;
e.Handled = true;
zoomDelta += e.Delta * 12;
img.Margin = new Thickness(zoomDelta);
}
Source code for “MouseWheelHelper” can be downloaded from here
.
Source code for example project can be downloaded from here
.
PS
I’m not responsible for any damage that may be caused by using this post or its content. Any materials in this post were provided AS IS without any changes and other meanings.
Technorati Tags:
.Net,
UI,
Example,
C#,
MS Framework 3.0,
Silverlight,
Code Example,
MS Blend,
MS Visual Studio 2008,
MS Framework 3.5,
UX,
XAML,
DEV,
MS Blend 2.0