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).

1  
!7
2  
3  
cm UserActivityDetector > DynBigNumber {
4  
  long lastActivity;
5  
  transient long persistedLastActivity;
6  
  transient Pt lastMousePosition;
7  
  
8  
  start {
9  
    setDescription("LAST ACTIVITY");
10  
    //dm_startKeyLogger(); // crashes on some machines
11  
    persistedLastActivity = lastActivity;
12  
    dm_vmBus_onMessages(r activity,
13  
      'keyDown, 'javaKeyEvent, 'speechRecognized_raw);
14  
    dm_doEvery(1.0, r {
15  
      Pt mouse = toPt(mousePosition());
16  
      if (neq(lastMousePosition, mouse)) {
17  
        lastMousePosition = mouse;
18  
        activity();
19  
      }
20  
      setValue(lastActivity == 0 ? "NEVER" : iround(secondsSinceLastActivity()) + " s ago");
21  
    });
22  
    dm_doEvery(5*60.0, r saveIfChanged);
23  
  }
24  
  
25  
  void saveIfChanged enter {
26  
    if (lastActivity != persistedLastActivity) {
27  
      persistedLastActivity = lastActivity;
28  
      change();
29  
    }
30  
  }
31  
  
32  
  // API
33  
  
34  
  void activity enter {
35  
    lastActivity = now();
36  
    vmBus_send userActivityDetected();
37  
  }
38  
  
39  
  double secondsSinceLastActivity() {
40  
    ret lastActivity == 0 ? infinity() : toSeconds(now()-lastActivity);
41  
  }
42  
}

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: 383 / 234066
Version history: 10 change(s)
Referenced in: [show references]