Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > BotCompany Repo | #1020622 // User Activity Detector

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1113K of libraries. Click here for Pure Java version (6551L/31K).

!7

cm UserActivityDetector > DynBigNumber {
  long lastActivity;
  transient long persistedLastActivity;
  transient Pt lastMousePosition;
  
  start {
    setDescription("LAST ACTIVITY");
    //dm_startKeyLogger(); // crashes on some machines
    persistedLastActivity = lastActivity;
    dm_vmBus_onMessages(r activity,
      'keyDown, 'javaKeyEvent, 'speechRecognized_raw);
    dm_doEvery(1.0, r {
      Pt mouse = toPt(mousePosition());
      if (neq(lastMousePosition, mouse)) {
        lastMousePosition = mouse;
        activity();
      }
      setValue(lastActivity == 0 ? "NEVER" : iround(secondsSinceLastActivity()) + " s ago");
    });
    dm_doEvery(5*60.0, r saveIfChanged);
  }
  
  void saveIfChanged enter {
    if (lastActivity != persistedLastActivity) {
      persistedLastActivity = lastActivity;
      change();
    }
  }
  
  // API
  
  void activity enter {
    lastActivity = now();
    vmBus_send userActivityDetected();
  }
  
  double secondsSinceLastActivity() {
    ret lastActivity == 0 ? infinity() : toSeconds(now()-lastActivity);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 10 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1020622
Snippet name: User Activity Detector
Eternal ID of this version: #1020622/11
Text MD5: bd7e820801ff162ceb227e17a39f5780
Transpilation MD5: 5d017e220fabeda09432e4987a42c2e8
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-24 15:45:21
Source code size: 1071 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 292 / 194502
Version history: 10 change(s)
Referenced in: [show references]