ui.root.setKeyHandler

미리 정의되지 않은 키가 있는 루트 패널에 keydown 이벤트 핸들러를 설정합니다. 사용자가 바인딩된 키 명령어를 누르면 핸들러가 한 번만 실행됩니다. 동일한 키가 설정된 최신 핸들러에 바인딩됩니다.

사용반환 값
ui.root.setKeyHandler(keyCode, handler, description)
인수유형세부정보
keyCodeList[ui.Key]|ui.Key키 코드 또는 키 코드 배열입니다. 예를 들어 ui.Key.A 또는 [ui.Key.SHIFT, ui.Key.A]입니다.
handler함수키 명령어의 핸들러입니다.
description문자열, 선택사항이 키 명령어를 설명하는 간단한 설명입니다. 설명은 단축키 메뉴에 표시됩니다.

코드 편집기 (JavaScript)

// Replace the default UI widgets with a few custom widgets.
// Print "Shift A" to the console when Shift+A is pressed.
ui.root.setKeyHandler(
  [ui.Key.SHIFT, ui.Key.A],
  function() {
    print('Shift A');
  },
  'A simple print'
);

// Create a solid black image.
var blackImage = ee.Image(1).visualize({palette: ['black']});

// Create a Layer object so we can easily manipulate its properties.
var blackLayer = ui.Map.Layer(blackImage, {}, 'Black Overlay', true);

// Add the layer to the Map.
Map.layers().add(blackLayer);

// Pressing the "b" key will toggle the layer on and off.
ui.root.setKeyHandler(ui.Key.B, function() {
  // Get the current visibility state.
  var isShown = blackLayer.getShown();

  // Set the visibility to the opposite of the current state.
  blackLayer.setShown(!isShown);

  // Print the status to the console.
  print('Black layer visible: ' + !isShown);
}, 'Toggle black layer');