Jump to content

Just when I thought it was safe to go back in the water....


Recommended Posts

I started playing with AutoIt on and off about three months ago. Thought I was really close on finishing one little project until yesterday when one of the "test" users walked in and said he could blow up the program by repeatedly and rapidly pressing the F1 and F2 keys.

The program works with Autocad. It was designed to allow users only access to two different screens (the drawing itself and the detail for that drawing) then disabling the mouse all but a few select keystrokes to allow them "read only" navigation.

He was correct. I sat there and went back and forth between the F1 and F2 keys fast and non-stop. It did something I couldn't believe. Down by the clock is the Intel Graphics Media icon and if you right click on that icon you get to a place where you can rotate the screen 90, 180 or 270 degrees. When this puppy crashed the up arrow set the screen to normal rotation, right arrow was set to 90 degree rotaion, down arrow was set to 180 degree rotation and left arrow was set to 270 degree roataion. How the mouse got down there and how the arrow keys got re-assigned to rotate the screen is so far past me it isn't funny. Another thing it did when it crashed was disable the mouse buttons. The mouse worked but the buttons didn't. It was a wild and wolly mess. My first thought was some kind of keyboard or mouse "buffer overflow" but figured I would be better off posting the code and getting some expert advise. It is very, very obvious I have no idea what I am doing.

It was suggested to me in another thread to get away from MouseClick and try and use ControlClick which I will attempt later today but I could really, really use some expert advise on my code and why it crashes with such disasterous results. Don't be shy. Bash away ;)

Autocad.AU3

Edited by ZiggyStardust
Link to comment
Share on other sites

Will be working on the ControlClicks later today. So there is no "buffer overflow" known to exist when "users" LOL do that? Can you give me an example of a "clicked" flag or any other routines to slow things down? Has a rapid, constant keyboard input been known to wreak havoc in programs?

Link to comment
Share on other sites

You are unblocking all keys when you enter each function. If you were to exclude F1 or F2 in the initial unblocking, I think that might fix it. I'm not sure though, I have never used this UDF.

Edit

Actually what I said may not be quite the right solution. You want to block those keys when you enter the function. You are unblocking all keys. Whatever your script is doing, I guess there will be a queue of calls to each function if you keep pressing the keys. How that results is anyone's guess.

Edited by czardas
Link to comment
Share on other sites

I see where you are comming from. It does seem a little redundant to first unblock and than re-block keys when entering and leaving the function. I had to unblock simple because with everything blocked I could not do any clicks or sends while everything is blocked. The way I am doing it results in recursion doesn't it?

Link to comment
Share on other sites

You just want to block the keys causing the problem. Unblocking everything allows key press messages to become queued. Blocking F1 and F2 keys when you enter the function and unblocking them before you exit the function is what I would expect.

Edited by czardas
Link to comment
Share on other sites

I see and agree. Actually when entering the function I would probably want to block everything wouldn't I? Then on exiting the function enable just what I want to enable? That way the function would execute once and only once no matter how many times they press the F1 or F2 keys. All keystrokes and mouse clicks would be disabled until the function completes.

Sorry about the above typos. I wasn't paying attention. I am going to have to play a little. When I first started playing with it and blocked everything send() and mouseclick() wouldn't work because the keyboard and mouse were disabled hence I had to unblock everything long enough to send() or mouseclick(). I couldn't find much in the documentation but it looks like controlclick and controlsend might still work with everything disabled. I'll give it a try.....

Link to comment
Share on other sites

How about something like...

#include <BlockInputEx.au3>
Global $MouseSpeed = 0
Global $Time = 1000
Global $DrawingTimer = 1001
Global $DetailTimer = 1001
; Set the quit key sequence
HotKeySet("^!+{ESC}", "Quit") ;crtl-alt-shift-esc
HotKeySet("{F1}", "Drawing")
HotKeySet("{F2}", "Detail")

While 1
Sleep(1000)
WEnd
Func Drawing()
If TimerDiff($DrawingTimer) < $Time Then Return ;bail out of function if less than specified time has passed
_BlockInputEx(0)
MouseClick("left", 164, 30, 1, $MouseSpeed)
MouseClick("left", 181, 53, 1, $MouseSpeed)
MouseClick("left", 995, 500, 1, $MouseSpeed)
_BlockInputEX(1, "{F1}|{F2}|{UP}|{DOWN}|{PGUP}|{PGDN}")
$DrawingTimer = TimerInit() ;reset timer
EndFunc   ;==>Drawing
Func Detail()
If TimerDiff($DetailTimer) < $Time Then Return
_BlockInputEx(0)
MouseClick("left", 164, 30, 1, $MouseSpeed)
MouseClick("left", 186, 96, 1, $MouseSpeed)
MouseClick("left", 182, 97, 1, $MouseSpeed)
MouseClick("left", 995, 500, 1, $MouseSpeed)
_BlockInputEx(1, "{F1}|{F2}|{LEFT}|{RIGHT}|{UP}|{DOWN}|{PGUP}|{PGDN}")
$DetailTimer = TimerInit()
EndFunc   ;==>Detail
Func Quit()
_BlockInputEx(0)
HotKeySet("{F5}")
HotKeySet("{F11}")
Exit
EndFunc   ;==>Quit

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

The program works with Autocad. It was designed to allow users only access to two different screens (the drawing itself and the detail for that drawing) then disabling the mouse all but a few select keystrokes to allow them "read only" navigation.

Why not use a free Autodesk read only DWG/DXF viewer instead?

http://usa.autodesk.com/adsk/servlet/pc/index?id=6703438&siteID=123112

I see fascists...

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...