Skip to content

All your computers and your phone/iPhone, working as one desk. Screens, apps, files, clipboard, calls, texts, notifications, mouse and keyboard, shared between Mac, Windows, Linux , Android, Web and ios / ipados . Free and open source. No account, no cloud, and no shared network needed.

4.2 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Keyboard tab: typing follows the pointer. The Hotkey card (double-tap = mouse and keyboard back
// here; keyboard-only switching), then two direction cards; the directions are the
// same switches as on the Cursor tab. Behaviour: kvm.js and windows-helper.
'use strict';

UI.tab({
  id: 'keyboard',
  for: ['computer', 'android', 'tv'], // iOS takes no mouse or keyboard from an app (shared/ui-kinds.js)
  order: 30,
  title: 'Keyboard',
  color: 'linear-gradient(#d1d1d6, #8e8e93)',
  desc: 'Type on whichever computer the pointer is on.',
  master: { get: (s) => s.kvm.keyboard, set: (v) => UI.api.setKvm({ keyboard: v }) },
  badge: (s) => (s.kvm.keyboard ? 'on' : ''),
  build(body) {
    const { api } = UI;
    const t = (...args) => I18n.t(...args);
    // The hotkey itself (double-tap: cursor sharing on or off) is on the Mouse page. Here only its use for
    // the keyboard alone, one-to-one: in Multi-device the keyboard follows the selected device.
    // Cursor sharing off by its switch or the hotkey (kvm.linked) leaves kvm.mouse on: keyboard-only
    // switching needs the keyboard shared and only the cursor off, so turning it on swaps one for the other.
    let cursorOff = false;
    const switchSw = UI.switch((v) => api.setKvm(v && cursorOff ? { hotkeySwitch: true, mouse: false, shared: true } : { hotkeySwitch: v }), { label: t('Switch the keyboard with the mouse sharing shortcut') });
    const switchRow = UI.row(t('Switch the keyboard with the mouse sharing shortcut'), '', [switchSw], { literal: true });
    const swap = UI.switch((v) => api.setKeys({ swapCtrlCmd: v }), { label: t('Swap Ctrl and Command') });
    const otherHotkey = UI.row('', '', [], { literal: true });
    const swapRow = UI.row(t('⌘ works as Ctrl'), t('So ⌘C copies here'), [swap]);
    const shortcutsRow = UI.row(t('Shortcuts on {name}'), t('Ctrl works as ⌘, so Ctrl+C copies there'));
    const status = UI.inputStatus();
    const pair = UI.dirCards(
      { on: { get: (s) => s.kvm.beDriven, set: (v) => api.setKvm({ beDriven: v }) }, label: t('Type on {me} with {name}’s keyboard'), rows: [otherHotkey, swapRow] },
      { on: { get: (s) => s.kvm.driveOther, set: (v) => api.setKvm({ driveOther: v }) }, label: t('Type on {name} with {me}’s keyboard'), rows: [shortcutsRow] },
    );

    const switchCard = UI.card(t('Keyboard switching'), [switchRow], { cls: 'keep-on' });
    const jump = UI.jumpCard ? UI.jumpCard() : null; // Multi-device: Jump to a device (shared/ui-jump.js)
    body.append(
      switchCard,
      pair.el,
      UI.card(t('Right now'), [status], { cls: 'keep-on' }),
    );
    const modMap = UI.modMapCard ? UI.modMapCard() : null; // Modifier keys (shared/ui-modmap.js)
    if (modMap) body.append(modMap.el);
    if (jump) body.append(jump.el);

    // Multi-device: which device's mouse and keyboard goes to which (shared/ui-matrix.js), as on Clipboard.
    const grid = window.MeshMatrix ? MeshMatrix.create({ feature: 'cursor', toggle: (id, f, dir, on) => UI.api.setConsent(id, f, dir, on) }) : null;
    const gridCard = grid ? UI.card(I18n.t('Devices'), [grid.el]) : null;
    if (gridCard) body.append(gridCard);
    return (s) => {
      if (gridCard) { gridCard.hidden = !s.mesh; if (s.mesh) grid.render(s.matrix); }
      if (jump) jump.update(s);
      if (modMap) modMap.update(s);
      const p = UI.peer(s);
      pair.update(s);
      status.update(s);
      switchCard.hidden = !!s.mesh; // Multi-device: not offered
      // Keyboard-only switching exists only while the pointer isn't shared (Cursor off, either way).
      cursorOff = !s.kvm.mouse || s.kvm.linked === false;
      switchSw.set(s.kvm.hotkeySwitch && !s.kvm.mouse);
      switchSw.disable(!cursorOff);
      switchRow.setHint(!cursorOff ? t('Only while mouse sharing is off') : t('Double-tap the shortcut to type on {device} and back', { device: p.the }));
      otherHotkey.label.textContent = t('Hotkey on {device}', { device: p.the });
      otherHotkey.setHint(t('Set in TwinDesk on {device}', { device: p.the }));
      // Ctrl/Cmd swapping only between a Mac and a PC.
      swapRow.hidden = p.os !== 'mac';
      shortcutsRow.hidden = p.os !== 'mac';
      swap.set(s.keys.swapCtrlCmd);
    };
  },
});