Library imports requires for 'Keyboard' and 'Keys'

时间:2016-02-12 21:40:00

标签: c# xaml universal

I am trying to write an event handler for when the space key is pressed, but it gives the error

The name 'keys (or keyboard)' does not exist in the current context.

I'm guessing I'm missing some library imports for these two methods.

Am I right? If so what are the imports I need to make? If not what do I need to do to make this work?

Thanks!

_

2 个答案:

答案 0 :(得分:0)

The Keys $('img').on('click', function() { var ind = $(this).index(); if ($(this).data("moved")) { // check if this is moved. If it is that means it was pushed back // before previous item so we're gonna move it after again $(this).data("moved",false).insertAfter($(this).next("img")); } else if (ind % 2 == 1 && !$(this).prev("img").hasClass("imgwidth") && !$(this).hasClass("imgwidth")) { // check if the item is on 2nd column by % calculation // if it is and previous item isn't expanded and it is also not expanded yet // this means we're gonna put this one before previous one $(this).data("moved",true).insertBefore($(this).prev("img")); } else if (ind % 2 == 1 && $(this).prev("img").data("moved") && !$(this).hasClass("imgwidth")) { // if it's on the 2nd column and previous one has data moved and // this one is not expanded yet // that means this one was actually before in the first place so // we're gonna put it back and remove data on the next one $(this).insertBefore($(this).prev("img")); $(this).prev("img").data("moved", false) } else if (ind % 2 == 0 && $(this).next("img").has("imgwidth") && $(this).hasClass("imgwidth")) { // if it's on the 1st column and next img is expanded and // this one is also expanded, next one needs to be pushed before this // and have data true $(this).insertAfter($(this).next("img")); $(this).prev("img").data("moved", true) } $(this).toggleClass('imgwidth'); }); comes from enum. (WinForms)

Keyboard.IsKeyDown comes from System.Windows.Forms.dll. (WPF)

Don't mix these two.

PresentationCore.dll takes a Key KeyBoard.IsKeyDown parameter which comes from enum, not a WindowsBase.dll Keys parameter.

Update

I see now that you're developing a Universal Windows App.

You should do it like this in that case:

enum

References in my project:

References

答案 1 :(得分:0)

See System.Windows.Input or System.Windows.Forms depending on your application structure.

https://msdn.microsoft.com/en-us/library/system.windows.input(v=vs.110).aspx