clipboardEvents.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Gather the list of clipboard event types as constants.
  3. */
  4. export class ClipboardEventTypes {
  5. /**
  6. * The clipboard event is fired when a copy command is active (pressed).
  7. */
  8. public static readonly COPY = 0x01; //
  9. /**
  10. * The clipboard event is fired when a cut command is active (pressed).
  11. */
  12. public static readonly CUT = 0x02;
  13. /**
  14. * The clipboard event is fired when a paste command is active (pressed).
  15. */
  16. public static readonly PASTE = 0x03;
  17. }
  18. /**
  19. * This class is used to store clipboard related info for the onClipboardObservable event.
  20. */
  21. export class ClipboardInfo {
  22. /**
  23. *Creates an instance of ClipboardInfo.
  24. * @param type Defines the type of event (BABYLON.ClipboardEventTypes)
  25. * @param event Defines the related dom event
  26. */
  27. constructor(
  28. /**
  29. * Defines the type of event (BABYLON.ClipboardEventTypes)
  30. */
  31. public type: number,
  32. /**
  33. * Defines the related dom event
  34. */
  35. public event: ClipboardEvent) {
  36. }
  37. /**
  38. * Get the clipboard event's type from the keycode.
  39. * @param keyCode Defines the keyCode for the current keyboard event.
  40. * @return {number}
  41. */
  42. public static GetTypeFromCharacter(keyCode: number): number {
  43. let charCode = keyCode;
  44. //TODO: add codes for extended ASCII
  45. switch (charCode) {
  46. case 67: return ClipboardEventTypes.COPY;
  47. case 86: return ClipboardEventTypes.PASTE;
  48. case 88: return ClipboardEventTypes.CUT;
  49. default: return -1;
  50. }
  51. }
  52. }