flat assembler
Message board for the users of flat assembler.

Index > Windows > Inactivity time system wide

Author
Thread Post new topic Reply to topic
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 04 Sep 2004, 19:49
Please can you help me with a document url or would you write down how to
make a very simple systemwide user idle timeout, the same that Windows use to start screensaver: which API I must call and what are the parameters?
Question
Exactly, I want to display a little text, when I don't touch the keyboard and mouse for 5 minutes. Thanks in advance!
Confused

I tried google with 10 variations of keywords and 10 pages of every results and nothing... Sad


Last edited by MACi on 05 Sep 2004, 21:09; edited 1 time in total
Post 04 Sep 2004, 19:49
View user's profile Send private message Reply with quote
Foamplast



Joined: 07 May 2004
Posts: 36
Location: Saratov, Russia
Foamplast 04 Sep 2004, 22:05
I advice you to use mouse and keyboard hooks. So then, everytime you receive a message from keyboard or mouse you may set a timer for 5 minutes, killing previous timer if there is one. If the user works, you are frequently killing your timer. If the user doesn't touch keybord and mouse, your timer will start a screensaver.
Post 04 Sep 2004, 22:05
View user's profile Send private message Visit poster's website Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 05 Sep 2004, 17:08
Okay... but I was doing serious asm coding in DOS era last time...
Can you help me with some code snippets, how to do, please?
Post 05 Sep 2004, 17:08
View user's profile Send private message Reply with quote
DEMON



Joined: 01 Aug 2004
Posts: 26
Location: Republic of Belarus
DEMON 05 Sep 2004, 21:15
Read ICZELION's tutorials Very Happy
There you can find information about hook's
Post 05 Sep 2004, 21:15
View user's profile Send private message Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 05 Sep 2004, 21:43
I've downloaded and searched through many tutorials (also Iczelion's), but didn't found hooks+systemwidetimers examples... Sad
Post 05 Sep 2004, 21:43
View user's profile Send private message Reply with quote
Foamplast



Joined: 07 May 2004
Posts: 36
Location: Saratov, Russia
Foamplast 06 Sep 2004, 22:12
Well, I always wonder why do people study someone's tutorials, not official documents. If you are going to program Window's applications you should know what method of communication this OS provides. This doesn't depend on language: asm, C, Pascal or something else. ICZELION's tutorials are good enough to understand principles of Windows assembly programming, but he can not re-tell all MSDN.

I advice you to study MSDN articles about hooks.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks.asp
Post 06 Sep 2004, 22:12
View user's profile Send private message Visit poster's website Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 07 Sep 2004, 06:22
Thanks!
So I find useful this msdn source and also I've found hooks example in Iczelion's tutorial #24, but win32 is yet strange for me (and I don't have enough free time to play much with masm32 code written for another purpose), so can anybody help with some code snippets, how to do it in a real world example, and also with some timer code snippets (you know, just simple to display a little text, when I don't touch the keyboard and mouse for some minutes), please? Confused

_________________
MACi
Post 07 Sep 2004, 06:22
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 09 Sep 2004, 00:00
There's a couple of ways to handle this - I'm assuming you're using a hook (although there's probably other ways - hooks should be avoided if you can, as they take system resources and can cause instability if not written properly).

Anyway, each time your hook gets fired and you detect a keypress, note current time in some variable (use GetLocalTime, GetSystemTime, or GetTickCount to get time). Either use WM_TIMER or a separate Thread to fire periodically - try to make it sleep as long as possible while not causing timing problems (with five minutes a one-minute sleep would be fine, and not take too much system resources).

Anyway, when checking timer/thread is fired, you get system time again, compare the difference between current system time and last hook-fire time - if larger than your period, act Smile
Post 09 Sep 2004, 00:00
View user's profile Send private message Visit poster's website Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 09 Sep 2004, 07:23
Thanks, that was closer, but... there are some unclear areas, how to do...
...this doesn't work, it even cannot get to hookproc:

Code:
include '%fasminc%\win32ax.inc'

.code
 start:

 invoke SetWindowsHookEx, WH_KEYBOARD, hookproc, 0, 0
 invoke ExitProcess, 0

.end start

proc hookproc, hwnd, uMsg, idEvent, dwTime
 invoke SetTimer, 0, 1, 1000, timerproc 
 invoke MessageBox, HWND_DESKTOP, "hook installed", "hook", MB_OK
 return
endp 

proc timerproc, hwnd, uMsg, idEvent, dwTime
 invoke KillTimer, 0, 1
 invoke MessageBox, HWND_DESKTOP, "timer finished", "timer", MB_OK
 return
endp
    


...and for the mouse also the same hook with WH_MOUSE to the same hookproc?

_________________
MACi
Post 09 Sep 2004, 07:23
View user's profile Send private message Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 21 Sep 2004, 08:32
nobody can help???
Post 21 Sep 2004, 08:32
View user's profile Send private message Reply with quote
omega_red



Joined: 13 Mar 2004
Posts: 19
Location: Poland
omega_red 21 Sep 2004, 09:58
Check what SetWindowsHook returns. Check GetLastError. Because you're setting global hook, HookProc has to be in DLL.
Post 21 Sep 2004, 09:58
View user's profile Send private message Visit poster's website Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 21 Sep 2004, 20:32
I don't know how to code dll, but this is the smaller problem, if there are exact example source codes (and I saw those for dll), the biggest problem is win32asm is not transparent for me, this is 1000 miles away from DOS ASM, and when I don't see the source code then I cannot learn swirls and catches, how to code...

_________________
MACi
Post 21 Sep 2004, 20:32
View user's profile Send private message Reply with quote
Foamplast



Joined: 07 May 2004
Posts: 36
Location: Saratov, Russia
Foamplast 21 Sep 2004, 20:53
Hello!

The attached is an example of keyboard hooking. It is a simple keylogger that writes keystrokes pressed to the file named "C:\kbd.log". This program is written in NASM, but the syntax is very close to FASM.

You can easily port this to NASM and enjoy. Feel free to ask me any questions you may have.


Description:
Download
Filename: projectx.zip
Filesize: 7.48 KB
Downloaded: 405 Time(s)

Post 21 Sep 2004, 20:53
View user's profile Send private message Visit poster's website Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 23 Sep 2004, 21:25
Thanks, I'll examine this

_________________
MACi
Post 23 Sep 2004, 21:25
View user's profile Send private message Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 01 Oct 2004, 17:48
I stucked on this Sad
I think I'll give a try to iczelion's tutor#24 combined with my own code above... it'll be hard for a dos coder... Confused

_________________
MACi
Post 01 Oct 2004, 17:48
View user's profile Send private message Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 12 Nov 2004, 13:29
doesn't work! Crying or Very sad Mad
Code:
include '%fasminc%\win32ax.inc'

.data

hookflag dd FALSE
hook dd ?

.code
start:

.if   [hookflag],e,FALSE
 invoke   SetWindowsHookEx, WH_MOUSE, hookproc, 0, 0
 mov      [hook],eax
 .if      eax,ne,0
  mov       [hookflag],TRUE
 .endif
 invoke   Sleep, 30000
 invoke ExitProcess, 0
.else
 invoke      UnhookWindowsHookEx,[hook]
 invoke   ExitProcess, 0
.endif

.end start

proc hookproc, nCode, wParam, lParam
 invoke       CallNextHookEx,[hook],[nCode],[wParam],[lParam]
 invoke      SetTimer, 0, 1, 1000, timerproc
 invoke      MessageBox, HWND_DESKTOP, "hook started", "hook", MB_OK
 return
endp

proc timerproc, hWnd, uMsg, idEvent, dwTime
 invoke    KillTimer, 0, 1
 invoke      MessageBox, HWND_DESKTOP, "timer finished", "timer", MB_OK
 invoke       UnhookWindowsHookEx,[hook]
 return
endp
    

_________________
MACi
Post 12 Nov 2004, 13:29
View user's profile Send private message Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 16 Nov 2004, 09:06
HELP PLEASE!

_________________
MACi
Post 16 Nov 2004, 09:06
View user's profile Send private message Reply with quote
MACi



Joined: 04 Sep 2004
Posts: 12
Location: Hungary
MACi 17 Nov 2004, 11:54
After many sleepless nights with writing and modifying and rewriting code... I've made it!

Can I think about myself, I'm the best asm coder in this area, because only I can do this and nobody could effectively help? Wink Moreover because this code is only one 2k exe and no dlls? Wink
Not bad from a win32 newbie, eh? Wink

_________________
MACi
Post 17 Nov 2004, 11:54
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.