本文整理匯總了Java中com.google.gwt.user.client.Event.getKeyCode方法的典型用法代碼示例。如果您正苦於以下問題:Java Event.getKeyCode方法的具體用法?Java Event.getKeyCode怎麽用?Java Event.getKeyCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.gwt.user.client.Event
的用法示例。
在下文中一共展示了Event.getKeyCode方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onBrowserEvent
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
@Override
public void onBrowserEvent(Event event) {
if (!isEnabled()) return;
super.onBrowserEvent(event);
if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
int type = DOM.eventGetType(event);
char keyCode = (char) event.getKeyCode();
switch (type) {
case Event.ONKEYDOWN:
if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') {
if (iDown != null) setResource(iDown);
}
break;
case Event.ONKEYUP:
if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') {
setResource(iUp);
onClick();
}
break;
}
}
}
示例2: onEventPreview
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
@Override
public boolean onEventPreview(Event event) {
int type = DOM.eventGetType(event);
if ((type == Event.ONCLICK || type == Event.ONTOUCHEND)
&& event.getEventTarget() != null) {
Element target = Element.as(event.getEventTarget());
if (target.getClassName() != null && target.getClassName().contains(CUBA_NOTIFICATION_MODALITY_CURTAIN)) {
hide();
return false;
}
}
if (type == Event.ONKEYDOWN && event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
if (!getElement().getClassName().contains(TRAY_STYLE)) {
hide();
return false;
}
}
return super.onEventPreview(event);
}
示例3: onBrowserEvent
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
@Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
int type = DOM.eventGetType(event);
char keyCode = (char) event.getKeyCode();
switch (type) {
case Event.ONKEYUP:
if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r')
onClick();
break;
}
}
}
示例4: onBrowserEvent
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
@Override
public void onBrowserEvent(Event event) {
if (event.getTypeInt() == Event.ONKEYUP && event.getKeyCode() == KeyCodes.KEY_SPACE) {
onClick();
}
if (event.getTypeInt() == Event.ONCLICK) {
setValue(!getValue());
}
super.onBrowserEvent(event);
}
示例5: onBrowserEvent
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
@Override
public void onBrowserEvent(Event event) {
int type = DOM.eventGetType(event);
if (type == Event.ONKEYDOWN
&& event.getKeyCode() == KeyCodes.KEY_ENTER
&& !event.getAltKey()
&& !event.getShiftKey()
&& !event.getCtrlKey()) {
event.stopPropagation();
return;
}
super.onBrowserEvent(event);
}
示例6: getKeyCode
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
/**
* Wrapper for GWT's get[Key Char]Code() that conflates the two values. If
* there is no keyCode present, it returns charCode instead. This matches the
* values in {{@link #keyMap} above.
*/
public static int getKeyCode(Event evt) {
int keyCode = evt.getKeyCode();
if (keyCode == 0) {
keyCode = evt.getCharCode();
}
return keyCode;
}
示例7: handleKeyboardEvents
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
@Override
protected boolean handleKeyboardEvents(Event event) {
int type = DOM.eventGetType(event);
// Synthesize clicks based on keyboard events AFTER the normal key
// handling.
if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
switch (type) {
case Event.ONKEYDOWN:
// Button should not react on shortcuts with ENTER and SPACE
if (isShortcut(event)
&& (event.getKeyCode() == KeyCodes.KEY_ENTER
|| event.getKeyCode() == KeyCodes.KEY_SPACE)) {
return true;
}
// Stop propagation when the user starts pressing a button that
// we are handling to prevent actions from getting triggered
if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
isFocusing = true;
event.preventDefault();
event.stopPropagation();
return true;
} else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
isFocusing = true;
event.stopPropagation();
return true;
} else if (event.getKeyCode() == KeyCodes.KEY_DOWN) {
isFocusing = true;
event.stopPropagation();
}
break;
// CAUTION IE sometimes does not generate ONKEYPRESS for ENTER, so we override default Vaadin behavior
case Event.ONKEYUP:
if (isFocusing) {
if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
isFocusing = false;
onClick();
event.stopPropagation();
event.preventDefault();
return true;
} else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
isFocusing = false;
onClick();
event.stopPropagation();
event.preventDefault();
return true;
} else if (event.getKeyCode() == KeyCodes.KEY_DOWN) {
isFocusing = false;
onClick();
event.stopPropagation();
event.preventDefault();
return true;
}
} else if (isShortcut(event)
&& (event.getKeyCode() == KeyCodes.KEY_ENTER
|| event.getKeyCode() == KeyCodes.KEY_SPACE)) {
return true;
}
break;
case Event.ONKEYPRESS: {
// Button should not react on shortcuts with ENTER and SPACE
if (isShortcut(event)
&& (event.getKeyCode() == KeyCodes.KEY_ENTER
|| event.getKeyCode() == KeyCodes.KEY_SPACE)) {
return true;
}
}
}
}
return false;
}
示例8: handleKeyboardEvents
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
@Override
protected boolean handleKeyboardEvents(Event event) {
int type = DOM.eventGetType(event);
// Synthesize clicks based on keyboard events AFTER the normal key
// handling.
if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
switch (type) {
case Event.ONKEYDOWN:
// Button should not react on shortcuts with ENTER and SPACE
if (isShortcut(event)
&& (event.getKeyCode() == KeyCodes.KEY_ENTER
|| event.getKeyCode() == KeyCodes.KEY_SPACE)) {
return true;
}
// Stop propagation when the user starts pressing a button that
// we are handling to prevent actions from getting triggered
if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
isFocusing = true;
event.preventDefault();
event.stopPropagation();
return true;
} else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
isFocusing = true;
event.stopPropagation();
return true;
}
break;
// CAUTION IE sometimes does not generate ONKEYPRESS for ENTER, so we override default Vaadin behavior
case Event.ONKEYUP:
if (isFocusing) {
if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
isFocusing = false;
onClick();
event.stopPropagation();
event.preventDefault();
return true;
} else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
isFocusing = false;
onClick();
event.stopPropagation();
event.preventDefault();
return true;
}
} else if (isShortcut(event)
&& (event.getKeyCode() == KeyCodes.KEY_ENTER
|| event.getKeyCode() == KeyCodes.KEY_SPACE)) {
return true;
}
break;
case Event.ONKEYPRESS: {
// Button should not react on shortcuts with ENTER and SPACE
if (isShortcut(event)
&& (event.getKeyCode() == KeyCodes.KEY_ENTER
|| event.getKeyCode() == KeyCodes.KEY_SPACE)) {
return true;
}
}
}
}
return false;
}
示例9: onPreviewNativeEvent
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
@Override
public void onPreviewNativeEvent(NativePreviewEvent previewEvent) {
if (autoHiders.isEmpty()) {
return;
}
// TODO(danilatos,user,user): Push signal down a layer - clean this up.
Event event = Event.as(previewEvent.getNativeEvent());
int lowLevelType = event.getTypeInt();
// TODO(danilatos): Insert this logic deeply rather than
// sprinkling it in event handlers. Also the return value
// of onEventPreview is the reverse of signal handlers.
SignalEvent signal = SignalEventImpl.create(event, false);
if (signal == null) {
return;
}
// Key events (excluding escape) and mousewheel events use hideTopmostAutoHiderForKeyEvent
if (lowLevelType == Event.ONMOUSEWHEEL || signal.isKeyEvent()) {
if (hideTopmostAutoHiderForKeyEvent(false)) {
// TODO(user): We don't call previewEvent.cancel() here, since for the floating-buttons
// menu we want, for example, space-bar to still shift focus to the next blip.
// The to-do is to audit the previewEvent.cancel call below and see why it's there (and if
// it's not needed, eliminate it).
return;
}
}
// Pressing escape at any time causes us to close and discard the event.
if (signal.getKeySignalType() == KeySignalType.NOEFFECT &&
event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
if (hideTopmostAutoHiderForKeyEvent(true)) {
previewEvent.cancel();
return;
}
}
// Click events and mouse-wheel events that fall through use hideAllAfter.
if (lowLevelType == Event.ONMOUSEDOWN || lowLevelType == Event.ONMOUSEWHEEL) {
hideAllAfter(signal.getTarget());
}
// Otherwise we don't do anything and the event continues as usual.
}
示例10: key
import com.google.gwt.user.client.Event; //導入方法依賴的package包/類
/**
* @return String describing the event's key code, e.g.,
* " 64 'a'"
*/
private static String key(Event event) {
return " " + event.getKeyCode() + " '" + (char) event.getKeyCode() + "'";
}