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 911K of libraries. Click here for Pure Java version (4713L/23K).

!7

cmodule 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);
    doEvery(1.0, r {
      Pt mouse = toPt(mousePosition());
      if (neq(lastMousePosition, mouse)) {
        lastMousePosition = mouse;
        activity();
      }
      setValue(lastActivity == 0 ? "NEVER" : iround(secondsSinceLastActivity()) + " s ago");
    });
    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   

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

No comments. add comment

Snippet ID: #1020622
Snippet name: User Activity Detector
Eternal ID of this version: #1020622/10
Text MD5: 54770ee8ded9844073af12db88bf34f0
Transpilation MD5: dab65d4dd2e68313481a92bf974eaef7
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: 2020-09-04 16:12:00
Source code size: 1111 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 163 / 57408
Version history: 9 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1020622 & http://1020622.tinybrain.de