Jump to content

how to know if key was sent by physical keyboard or by Send() ?


Recommended Posts

hello all,

i have this scenario:

script1 is doing a task which is very I/O intensive. in order to minimize impact on user workflow, it starts its activity when the user is idle for some time (assuming the user left his desk). when a mouse/keyboard action is detected, script2 assumes the user has returned, therefore pauses until the idle time is reached again. for that, i use the function _Timer_GetIdleTime()

this was working well for long time now.

now, i have another script, script2 which is doing a completely unrelated task. it is running in the background monitoring an application, sometimes using send() to respond to dialogs created by that application.

 
that alone also works very well.
 
now, these two tasks are supposed to be consolidated into one physical host.
you see the problem:
 
if script1 and script2 launch independently, then script1 detects the occasional send() of script2 as a user activity, and pauses without need.
 
now here is the interesting thing:
 
if i make script1 launch script2, then script1 does not detect the send() of script2, and works as expected.
 
although i don't understand why this is, i can accept that as a solution. but performance-wise this is far from ideal. i would be happy if script1 is able by itself to tell if a key was sent by the physical keyboard or by send() of script2 (or any other script, for that matter).
 
another possible approach would be to check the idle time of mouse only (not keyboard), so only if the user moves the mouse then script1 pauses. but i don't know how to do this.
 
consolidating the scripts is not possible, as the scripts run with different credentials.
 
any help is welcome, thanks,
orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

hi orbs

according to this link, it is possible to discriminate virtual keys from real keys.

http://inputsimulator.codeplex.com/discussions/267233

(look at the bottom of that page)

if you know the C language maybe you can get something from that ....

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

thanks JohnOne! i switched to using mouse coordinates change to determine user activity, it works exactly as intended.

Pincopanco, unfortunately i'm not that strong on dll and that stuff, and since i have a working solution, i will not investigate further.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

  • 3 weeks later...

I'm running into the same issue here with the mouse movement- I have a script that I have been trying to figure out how to run when the computer is idle but it takes control of the mouse- I was hoping to be able to enter my script back into a "pause" mode when the user comes back and uses the physical keyboard and mouse and not have the scripted keyboard actions work. Unfortunately my testing of the idle timer check shows that the script moving the mouse considers it input and thus never allows it to think the system is idle...

While 1
sleep(1000)
    MouseMove(3,5)
    MouseMove(30,555)
    ConsoleWrite("Idle time| " & _Timer_GetIdleTime() / 1000 & "seconds" & @LF)
wend

What a huge bummer- my only work around so far has been setting an ini flag in an ini I already have set up for the script to communicate with other scripts I wrote. I had not thought about using the registry which may be a smarter approach to creating a flag. 

I was really hoping someone may have located an alternative solution that would aid in the op's post here which is the same issue I'm having. The only thing I could think of was monitoring the actual hardware IO but that's out of my scope of abilities.

-K

Link to comment
Share on other sites

Don't use MouseMoves and MouseClicks, use ControlClick instead.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Don't use MouseMoves and MouseClicks, use ControlClick instead.

 

I really wish I could but this particular program I'm interacting with, a proprietary company program, does not show anything that I know or have figured out how to work with when I use the autoit window tool for the buttons. It is highly possible that I'm simply not code intelligent enough regarding window controlling. I have been relying on pure coordinate locations and the ImageSearch.dll to make my particular scripts function.

 

This is a menu list with buttons on it.

>>>> Control <<<<
Class: WindowsForms10.Window.8.app.0.378734a
Instance: 2
ClassnameNN: WindowsForms10.Window.8.app.0.378734a2
Name: ToolBar1
Advanced (Class): [NAME:ToolBar1]
ID: 2101344
Text:
Position: 0, 0
Size: 1276, 38
ControlClick Coords: 914, 22
Style: 0x56010000
ExStyle: 0x00000000
Handle: 0x00201060
 
This is a selection list...
>>>> Control <<<<
Class: WindowsForms10.Window.8.app.0.378734a
Instance: 2
ClassnameNN: WindowsForms10.Window.8.app.0.378734a2
Name: dgBSReprint
Advanced (Class): [NAME:dgBSReprint]
ID: 10096394
Text:
Position: 16, 40
Size: 400, 376
ControlClick Coords: 151, 147
Style: 0x56010000
ExStyle: 0x00000000
Handle: 0x009A0F0A
 
Then inside the following I have all sorts of buttons and lists of attachments that change
 
>>>> Control <<<<
Class: WindowsForms10.Window.8.app.0.378734a
Instance: 1
ClassnameNN: WindowsForms10.Window.8.app.0.378734a1
Name: dgvReport
Advanced (Class): [NAME:dgvReport]
ID: 398756
Text:
Position: 12, 44
Size: 743, 258
ControlClick Coords: 474, 55
Style: 0x56010000
ExStyle: 0x00000000
Handle: 0x000615A4
 
 

-K

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...