Hello,
I hope this isn't too much to ask for free, I have poor knowledge in programming or basic script creation..
I need a script which I can place in Windows 7 Startup folder and will do the following:
When Keyboard/Mouse disconnects (unplugged), launch the following script:
- Message box or command prompt window will pop-up containing the following:
- Computer will Logout in 60 Seconds (countdown) Press any key to continue..
- If true (any key is pressed), exit script..
- If false (no key is pressed), proceed to Logout.
You can change the Total Count of Mouse,Keyboard,HID into the actual Total Count of your PC using attached RawInput Devices Script.
Thank you sooooo much again, Guys! More Knowledge to you all!
AutoLogout when Mouse/Keyboard is unplugged
AutoLogout when Mouse/Keyboard is unplugged
Last edited by ivanz on 13 Jul 2018, 10:16, edited 3 times in total.
Re: AutoLogout when Mouse/Keyboard is unplugged
Ever entered a key with an intentionally unplugged keyboard?
Re: AutoLogout when Mouse/Keyboard is unplugged
Hello Sir,BoBo wrote:Ever entered a key with an intentionally unplugged keyboard?
The option is only when or if the keyboard was reconnected during the countdown..
Re: AutoLogout when Mouse/Keyboard is unplugged
i'm sorry but i really have no idea on how that script works and how it would help me..
i just post request here hoping someone would help..
will try to watch some youtube guide..
thank you..
i just post request here hoping someone would help..
will try to watch some youtube guide..
thank you..
Re: AutoLogout when Mouse/Keyboard is unplugged
In order to do so, you would probably need code which implements an API where you could get at this information.
Some APIs that I know of which have this info:
RawInput
DirectInput
Interception
Some APIs that I know of which have this info:
RawInput
DirectInput
Interception
- Delta Pythagorean
- Posts: 627
- Joined: 13 Feb 2017, 13:44
- Location: Somewhere in the US
- Contact:
Re: AutoLogout when Mouse/Keyboard is unplugged
I have a feeling you can use DllCall to detect whether a device was removed but I don't think you can detect if a keyboard was unplugged unless it has it's own process and/or tray icon.
[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat
Re: AutoLogout when Mouse/Keyboard is unplugged
Here you go, I wrote you a C# DLL that you can call from AHK to get this info.
Usage is simple, most of the code is using Lexikos' CLR lib to allow us to load the C# DLL
The DLL provides two functions: GetMouseCount() and GetKeyboardCount()
Two ZIPs are attached.
Demo.zip contains just the files you need to use this library
For those interested, the C# code is also super simple, I just use the SharpDX library:
Source.zip contains the Visual Studio project
Usage is simple, most of the code is using Lexikos' CLR lib to allow us to load the C# DLL
The DLL provides two functions: GetMouseCount() and GetKeyboardCount()
Code: Select all
#NoEnv
#SingleInstance force
#Include CLR.ahk
dllpath := "MouseKeyboardCount.dll"
if (!FileExist(dllpath)){
msgbox % "MouseKeyboardCount: DLL file " dllpath " not found"
ExitApp
}
asm := CLR_LoadLibrary(dllpath)
; Use CLR to instantiate a class from within the DLL
mkc := asm.CreateInstance("MouseKeyboardCount")
Loop {
ToolTip % "Mice: " mkc.GetMouseCount() " Keyboards: " mkc.GetKeyboardCount() " @ " A_TickCount
Sleep 1000
}
Demo.zip contains just the files you need to use this library
For those interested, the C# code is also super simple, I just use the SharpDX library:
Code: Select all
using SharpDX.DirectInput;
public class MouseKeyboardCount
{
static private DirectInput directInput = new DirectInput();
public int GetKeyboardCount()
{
var keyCount = 0;
var devices = directInput.GetDevices();
foreach (var deviceInstance in devices)
{
if (deviceInstance.Type == DeviceType.Keyboard)
{
keyCount++;
}
}
return keyCount;
}
public int GetMouseCount()
{
var mouseCount = 0;
var devices = directInput.GetDevices();
foreach (var deviceInstance in devices)
{
if (deviceInstance.Type == DeviceType.Mouse)
{
mouseCount++;
}
}
return mouseCount;
}
}
- Attachments
-
- Source.zip
- (168.28 KiB) Downloaded 56 times
-
- Demo.zip
- (160.09 KiB) Downloaded 70 times
Re: AutoLogout when Mouse/Keyboard is unplugged
Thank you very much Sir.. I can see active mouse/keyboard detection whenever i run the compiled test.ahk inside the Demo.zip.
I'm sorry to bother, but can you please incorporate this little "screensaver" log-off program to call/run whenever the mouse/keyboard value gets to (0)?
Please..
I'm sorry to bother, but can you please incorporate this little "screensaver" log-off program to call/run whenever the mouse/keyboard value gets to (0)?
Please..
- Attachments
-
- Screensaver.zip
- (184.31 KiB) Downloaded 60 times
Re: AutoLogout when Mouse/Keyboard is unplugged
very impressive evilC
Re: AutoLogout when Mouse/Keyboard is unplugged
evilC wrote:RawInput
Code: Select all
#NoEnv
DevCount := RI_GetDeviceCount()
MsgBox, 0, RawInput Devices, % "Total: " . DevCount.TC . "`n"
. "Mouse: " . DevCount.MC . "`n"
. "Keybd: " . DevCount.KC . "`n"
. "HID: " . DevCount.HC
Exitapp
; ================================================================================================================================
; Raw Input -> msdn.microsoft.com/en-us/library/windows/desktop/ms645536(v=vs.85).aspx
; GetRawInputDeviceList - Enumerates the raw input devices attached to the system.
; ================================================================================================================================
RI_GetDeviceCount() {
StructSize := A_PtrSize * 2 ; size of a RAWINPUTDEVICELIST structure
DevCount := 0
DllCall("GetRawInputDeviceList", "Ptr", 0, "UIntP", DevCount, "UInt", StructSize, "Int")
If (DevCount) {
VarSetCapacity(ListArr, StructSize * DevCount, 0) ; array of RAWINPUTDEVICELIST structures
If (DllCall("GetRawInputDeviceList", "Ptr", &ListArr, "UIntP", DevCount, "UInt", StructSize, "Int") = DevCount) {
Counters := {0: 0, 1: 0, 2: 0}
Addr := &ListArr
Loop, %DevCount% {
Counters[NumGet(Addr + A_PtrSize, "UInt")]++
Addr += StructSize
}
Return {HC: Counters[2], KC: Counters[1], MC: Counters[0], TC: DevCount}
}
}
Return False
}
; ================================================================================================================================
Re: AutoLogout when Mouse/Keyboard is unplugged
up..
ivanz wrote:Thank you very much Sir.. I can see active mouse/keyboard detection whenever i run the compiled test.ahk inside the Demo.zip.
I'm sorry to bother, but can you please incorporate this little "screensaver" log-off program to call/run whenever the mouse/keyboard value gets to (0)?
Please..
Re: AutoLogout when Mouse/Keyboard is unplugged
I used script from 'just me'
have Logitech wireless mouse & keyboard
start script and remove USB-Receiver
check variables for mouse or keyboard or HID and then possible to start a program ( here msgbox )
have Logitech wireless mouse & keyboard
start script and remove USB-Receiver
check variables for mouse or keyboard or HID and then possible to start a program ( here msgbox )
Code: Select all
;-------- https://autohotkey.com/boards/viewtopic.php?f=5&t=35986 ---
/*
check every 5-seconds and show msgbox for 2-seconds
when USB-Receiver is removed :
Total = 4
Mouse = 2
Keyboard= 2
HID = 0
otherwise :
Total = 11
Mouse = 3
Keyboard= 3
HID = 5
*/
#NoEnv
#persistent
settimer,aa,5000,on
gosub,aa
return
aa:
DevCount := RI_GetDeviceCount()
HID1:=DevCount.HC
if (HID1=0)
{
msgbox, 262208,>>> HID=0, % "Total: " . DevCount.TC . "`n"
. "Mouse: " . DevCount.MC . "`n"
. "Keybd: " . DevCount.KC . "`n"
. "HID: " . DevCount.HC,2
return
}
else
{
msgbox, 262208,RawInput Devices, % "Total: " . DevCount.TC . "`n"
. "Mouse: " . DevCount.MC . "`n"
. "Keybd: " . DevCount.KC . "`n"
. "HID: " . DevCount.HC,2
return
}
return
esc::exitapp
; ================================================================================================================================
; Raw Input -> msdn.microsoft.com/en-us/library/windows/desktop/ms645536(v=vs.85).aspx
; GetRawInputDeviceList - Enumerates the raw input devices attached to the system.
; ================================================================================================================================
RI_GetDeviceCount() {
StructSize := A_PtrSize * 2 ; size of a RAWINPUTDEVICELIST structure
DevCount := 0
DllCall("GetRawInputDeviceList", "Ptr", 0, "UIntP", DevCount, "UInt", StructSize, "Int")
If (DevCount) {
VarSetCapacity(ListArr, StructSize * DevCount, 0) ; array of RAWINPUTDEVICELIST structures
If (DllCall("GetRawInputDeviceList", "Ptr", &ListArr, "UIntP", DevCount, "UInt", StructSize, "Int") = DevCount) {
Counters := {0: 0, 1: 0, 2: 0}
Addr := &ListArr
Loop, %DevCount% {
Counters[NumGet(Addr + A_PtrSize, "UInt")]++
Addr += StructSize
}
Return {HC: Counters[2], KC: Counters[1], MC: Counters[0], TC: DevCount}
}
}
Return False
}
; ================================================================================================================================
Who is online
Users browsing this forum: a_bolog, Google [Bot] and 168 guests