-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring and windows support #14
Changes from 1 commit
f7bc0a6
ecd6e50
502cd47
2d6d06a
eda0520
2536797
96eaf5a
8728062
af8df52
6c4c318
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ logs | |
*.egg-info | ||
build | ||
dist | ||
*~ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from .afk import main | ||
|
||
import __main__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import aw_watcher_afk | ||
aw_watcher_afk.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import time | ||
|
||
import ctypes | ||
from ctypes import Structure, POINTER, WINFUNCTYPE, windll | ||
from ctypes.wintypes import BOOL, UINT, DWORD | ||
|
||
|
||
class LastInputInfo(Structure): | ||
_fields_ = [ | ||
("cbSize", UINT), | ||
("dwTime", DWORD) | ||
] | ||
|
||
|
||
def _getLastInputTick(): | ||
prototype = WINFUNCTYPE(BOOL, POINTER(LastInputInfo)) | ||
paramflags = (1, "lastinputinfo"), | ||
c_GetLastInputInfo = prototype(("GetLastInputInfo", ctypes.windll.user32), paramflags) | ||
|
||
l = LastInputInfo() | ||
l.cbSize = ctypes.sizeof(LastInputInfo) | ||
assert 0 != c_GetLastInputInfo(l) | ||
return l.dwTime | ||
|
||
|
||
def _getTickCount() -> int: | ||
prototype = WINFUNCTYPE(DWORD) | ||
paramflags = () | ||
c_GetTickCount = prototype(("GetTickCount", ctypes.windll.kernel32), paramflags) | ||
return c_GetTickCount() | ||
|
||
|
||
def time_since_last_input(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created an issue for this: #16 |
||
seconds_since_input = (_getTickCount() - _getLastInputTick())/1000 | ||
return seconds_since_input | ||
|
||
|
||
if __name__ == "__main__": | ||
while True: | ||
time.sleep(1) | ||
print(time_since_last_input()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to use GetTickCount64 instead.