Liberty BASIC Community Forum
« Detecting HID movements »

Welcome Guest. Please Login or Register.
Apr 28th, 2017, 4:50pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Detecting HID movements  (Read 682 times)
Simon
Full Member
ImageImageImage


member is offline

Avatar

My best friend is Alyce


Homepage PM

Gender: Male
Posts: 101
xx Detecting HID movements
« Thread started on: Oct 25th, 2011, 03:23am »

I want to be able to detect ANY input from a mouse or keyboard, just to detect whether the user is still working at PC.
I want to run my .bas in the background with nomainwin,
I want a function that executes if the user has NOT been working on a PC for 20 mins??

can I still use CallDLL #user32, "GetAsyncKeyState",_
in some way?
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5251
xx Re: Detecting HID movements
« Reply #1 on: Oct 25th, 2011, 04:40am »

If you research the GetAsyncKeystate you will find it returns three values. The key has not been pressed since you last checked, the key has been pressed and released since you last checked and the key is currently pressed. So it seems there is enough info in the response to tell you what you need to know.
User IP Logged

Simon
Full Member
ImageImageImage


member is offline

Avatar

My best friend is Alyce


Homepage PM

Gender: Male
Posts: 101
xx Re: Detecting HID movements
« Reply #2 on: Oct 25th, 2011, 05:09am »

I thnk I can't use it..

Return value Type: SHORT

If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. However, you should not rely on this last behavior; for more information, see the Remarks.

The return value is zero for the following cases:

•The current desktop is not the active desktop
•The foreground thread belongs to another process and the desktop does not allow the hook or the journal record.



Does anyone know how to detect keyboard/mouse action when .bas is not the focus?
User IP Logged

CS
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 60
xx Re: Detecting HID movements
« Reply #3 on: Oct 25th, 2011, 05:19am »

Hello, I don't know how but I would guess it would be along the lines of a screen saver.
User IP Logged

I read more than I write
Simon
Full Member
ImageImageImage


member is offline

Avatar

My best friend is Alyce


Homepage PM

Gender: Male
Posts: 101
xx Re: Detecting HID movements
« Reply #4 on: Oct 25th, 2011, 05:37am »

Hmmm>? I wonder if I can detect the CPU movements? ie.. if CPU is <1% load for 20 mins then... ?
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1618
xx Re: Detecting HID movements
« Reply #5 on: Oct 25th, 2011, 05:57am »

Really, if you make your program a screen saver and set timeout to 20 minutes, Windows will detect mouse movement etc and start it after 20 minutes of inactivity.

Just an easy way.
User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
xx Re: Detecting HID movements
« Reply #6 on: Oct 25th, 2011, 06:06am »

Quick demo. Ticks=milliseconds. The demo uses a timer to check time of lastinput info in five seconds. I ran it several times and each time got a value just over 5000, like 5290. This is just as I'd expect for a five second delay.

http://alycesrestaurant.com/systemidle.htm

Code:
struct LASTINPUTINFO,_
cbSize as ulong,_     'size of struct
tickCount as ulong    'tick count at last session input

LASTINPUTINFO.cbSize.struct=len(LASTINPUTINFO.struct)

print "Please wait and do not touch keyboard or mouse."
timer 5000, [getInfo]
wait

[getInfo]
timer 0
calldll #user32, "GetLastInputInfo",_ 'time of last input event
LASTINPUTINFO as struct,_   'struct to hold data
result as long              'nonzero=success

ticksLastInput=LASTINPUTINFO.tickCount.struct
print "Last input tick count: ";ticksLastInput

calldll #kernel32, "GetTickCount",_
startTicks as ulong  'ticks since system start

print "Ticks since system start ";startTicks
print "Idle ticks: ";startTicks-ticksLastInput
 
« Last Edit: Oct 25th, 2011, 06:59am by Admin » User IP Logged

CS
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 60
xx Re: Detecting HID movements
« Reply #7 on: Oct 25th, 2011, 06:23am »

on Oct 25th, 2011, 05:37am, Simon wrote:
Hmmm>? I wonder if I can detect the CPU movements? ie.. if CPU is <1% load for 20 mins then... ?


That would not work as most systems run background tasks such as indexing, defrag and anti-virus.
User IP Logged

I read more than I write
Simon
Full Member
ImageImageImage


member is offline

Avatar

My best friend is Alyce


Homepage PM

Gender: Male
Posts: 101
xx Re: Detecting HID movements
« Reply #8 on: Oct 25th, 2011, 08:01am »

Thankyou ALICE !! It worked PERECT¬!!! ;P



Code:
struct LASTINPUTINFO,_
cbSize as ulong,_     'size of struct
tickCount as ulong    'tick count at last session input
LASTINPUTINFO.cbSize.struct=len(LASTINPUTINFO.struct)
print "Please wait and do not touch keyboard or mouse."
timer 5000, [getInfo]
wait
[getInfo]
calldll #user32, "GetLastInputInfo",_ 'time of last input event
LASTINPUTINFO as struct,_   'struct to hold data
result as long              'nonzero=success
ticksLastInput=LASTINPUTINFO.tickCount.struct
calldll #kernel32, "GetTickCount",startTicks as ulong
idleTicks = startTicks-ticksLastInput
if idleTicks>5000 then
print "Idle for the past ";idleSecs+5;" seconds"
idleSecs = idleSecs + 5
else
idleSecs = 0
print "Interference Detected"
end if
wait

 
« Last Edit: Oct 25th, 2011, 08:03am by Simon » User IP Logged

Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
xx Re: Detecting HID movements
« Reply #9 on: Oct 25th, 2011, 10:55am »

Added to LBPE with more explanation.

http://lbpe.wikispaces.com/LastInputInfo

User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls