Thread: Silverlight and KeyDown

  1. #1
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630

    Silverlight and KeyDown

    So this is a kinda complex problem. I have a silverlight application that I have developed that relies on some key presses to function, when running this application it grabs the KeyDown and KeyUp events off the host user control, everything works great. Well this application has to be hosted inside of another silverlight application, so you could think of my application as a dll (after all it really is) and it gets loaded into the main application through reflection. This hosting application has a few buttons and you click one to launch the desired application. To get the key presses we first tried to capture the KeyDown/KeyUp events on the main user control and they did not fire at all. We then added KeyDown/KeyUp events to the buttons and are able to pass our Key events into the application however we can not pass in spacebar or enter this way. Is there a way to do this that I haven't thought of yet. I also tried to change the buttons to rectangles, which worked for the button press events, however the rectangle fails to keep focus so it also has no key events fire.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Here is probably your answer

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Thanks, that helps. Wonder why I didn't find that with google, is it just me or does google seem to suck lately?

    [Edit]
    Actually just got to the office and tried that and it has no effect. Still don't receive space/enter keys.
    Last edited by xds4lx; 08-18-2010 at 06:13 AM.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Ok, well was able to get something working but it required a few things. First we had to mark each button in the xaml with IsTabStop="false" then had to add an event in the application being loaded so that when its user control is loaded it first tells the silverlight plugin to focus and then the user control to focus, seems to be working good and passing all key presses on now.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed