This repository has been archived by the owner on Sep 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation and refactoring. New idle detection class
- Loading branch information
Showing
13 changed files
with
461 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ | |
*.MF | ||
*.sh | ||
/bin/ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package me.coley.simplejna; | ||
|
||
import com.sun.jna.platform.win32.Kernel32; | ||
import com.sun.jna.platform.win32.User32; | ||
|
||
/** | ||
* Utility for retrieving the idle time on Windows. | ||
* | ||
* @author ochafik | ||
*/ | ||
public class Idle { | ||
|
||
/** | ||
* Get the time elapsed since the last input event <i>((mouse or keyboard))</i> | ||
* in milliseconds. | ||
* | ||
* @return Time in milliseconds | ||
*/ | ||
public static int dxInputEventTime() { | ||
User32.LASTINPUTINFO lastInputInfo = new User32.LASTINPUTINFO(); | ||
User32.INSTANCE.GetLastInputInfo(lastInputInfo); | ||
return Kernel32.INSTANCE.GetTickCount() - lastInputInfo.dwTime; | ||
} | ||
|
||
public static enum State { | ||
UNKNOWN, ONLINE, IDLE, AWAY | ||
}; | ||
|
||
//@formatter:off | ||
/* | ||
public static void main(String[] args) { | ||
if (!System.getProperty("os.name").contains("Windows")) { | ||
System.err.println("ERROR: Only implemented on Windows"); | ||
System.exit(1); | ||
} | ||
State state = State.UNKNOWN; | ||
DateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss"); | ||
for (;;) { | ||
int idleSec = dxInputEventTime() / 1000; | ||
State newState = idleSec < 30 ? State.ONLINE : idleSec > 5 * 60 ? State.AWAY : State.IDLE; | ||
if (newState != state) { | ||
state = newState; | ||
System.out.println(dateFormat.format(new Date()) + " # " + state); | ||
} | ||
try { | ||
Thread.sleep(100); | ||
} catch (Exception ex) {} | ||
} | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.