Jump to content

Multiple Keypress


Recommended Posts

I wonder if someone could help me write this as my time is very limited.

I didn't see anything for decting a mouse click so I'm going to try and use a HotKetSet dection instead.

I'm going to have a PLC push a key (wired), say {Numpad1}, a number of times. I need AutoIt to count those times and then jump to a func that will play a sound.

Similiar to this...

HotKeySet("{Numpad1}", "Play1")
HotKeySet("{Numpad2}", "Play2")
HotKeySet("{ESC}", "Terminate")

Func Play1()
    SoundPlay("C:\3\Screams.mp3")
EndFunc

Func Play2()
    SoundPlay("C:\3\Howls.mp3")
EndFunc

While 1
    Sleep(100)
WEnd

Func Terminate()
    Exit 0
EndFunc

But now with only one HotKey. (I was going to wire into all 10 numpad keys but the keyboard matrix wiring clashes with my PLC output commons)

Hit {Numpad1} 3 times, it needs to go to Func Play3(). Hit {Numpad1} 5 times, it needs to go to Func Play5(). Etc.

Can someone help write this? It's for a haunted house and I have no time to play around with getting this to work.

tia

-Scott

Link to comment
Share on other sites

Try the following. The $TIMEOUT_PERIOD controls how quickly you have to press the key so that two presses count as 2 rather than 1 and 1.

(So don't make the timeout too short!)

Add more code to the select case block as needed.

Global $TIMEOUT_PERIOD = 500;value in milliseconds

Global $KeypressCount = 0
Global $timeOfLastPress = 0

HotKeySet("{Numpad1}", "KeyPress")
HotKeySet("{ESC}", "Terminate")

While 1
    If ($timeOfLastPress > 0) And (TimerDiff($timeOfLastPress) > $TIMEOUT_PERIOD) Then
        DoSound($keypressCount)
        $keypressCount = 0
        $timeOfLastPress = 0
    EndIf
    sleep(10)
Wend
Exit

Func KeyPress()
    $KeypressCount = $KeypressCount + 1
    $timeOfLastPress = TimerInit()
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func DoSound($count)
    Select
    Case 1 == $count
         SoundPlay("C:\3\Screams.mp3")
    Case 2 == $count
         SoundPlay("C:\3\Howls.mp3")
    EndSelect
EndFunc
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

To slow but...

HotKeySet("{Numpad1}", '_count')
HotKeySet("{ESC}", "Terminate")

Dim $count = 0
Dim $timer = TimerInit()
Dim $sounds = StringSplit( @WindowsDir & '\media\ding.wav|' & _
@WindowsDir & '\media\tada.wav|' & _
@WindowsDir & '\media\ringin.wav', '|')

AdlibEnable( '_play', 200)

While 1
    Sleep(100)
WEnd

Func _play()
    If ($count > 0) And (TimerDiff( $timer) > 500) Then
        If $count <= $sounds[0] Then
            SoundPlay( $sounds[$count])
        EndIf
        MsgBox( 0, '', $count)
        $count = 0
    EndIf
EndFunc

Func _count()
    $count += 1
    $timer = TimerInit()
EndFunc

Func Terminate()
    Exit 0
EndFunc
Edited by UP NORTH
Link to comment
Share on other sites

Try the following. The $TIMEOUT_PERIOD controls how quickly you have to press the key so that two presses count as 2 rather than 1 and 1.

(So don't make the timeout too short!)

Add more code to the select case block as needed.

Hey thanks Cyberslug! That seems to work great.

Thanks also for Up Norths version although I didn't check it out... no time no time!

~back to wiring~

-Scott

Link to comment
Share on other sites

The program worked without a hitch!

I had a Mitsubishi FX0s, an old Micromaster for more IO and a HP 233mhz PC that I found in the trash and loaded Win98 and Autoit on to play the sounds. The FX talked to the Micromaster via 4 wire IO using binary in the two programs. 0001, 0010, 0011, etc. I ended up seting up 3 different sounds in 3 different places (I wanted more but ran out of time).

We had a flying skeleton on a string with a speaker behind him.

A pirate in a hanging - jiggling cage with sound effect.

And a creepy lady with an automated knife drop, her head stood up and turned and the ultimate blood-curdling screaming sound I could find... cranked as loud as it could go!

Not to mention floresent black lights, strobes, spiders moving, other flying ghosts, motion sensors to know where people are at and a tall vampire guy (real life) hiding at the end for the final scare.

It turned out great and many of the kids (and parents) ran out of it and completely forgot about getting a treat. :o

According to my counters, about 1000 people went through this year.

Next year we are seriously concidering moving it out of the garage and into a big pole barn, maybe even charging money. B)

Thanks again for the help!

-Scott

Link to comment
Share on other sites

The program worked without a hitch!

I had a Mitsubishi FX0s, an old Micromaster for more IO and a HP 233mhz PC that I found in the trash and loaded Win98 and Autoit on to play the sounds. The FX talked to the Micromaster via 4 wire IO using binary in the two programs. 0001, 0010, 0011, etc. I ended up seting up 3 different sounds in 3 different places (I wanted more but ran out of time).

We had a flying skeleton on a string with a speaker behind him.

A pirate in a hanging - jiggling cage with sound effect.

And a creepy lady with an automated knife drop, her head stood up and turned and the ultimate blood-curdling screaming sound I could find... cranked as loud as it could go!

Not to mention floresent black lights, strobes, spiders moving, other flying ghosts, motion sensors to know where people are at and a tall vampire guy (real life) hiding at the end for the final scare.

It turned out great and many of the kids (and parents) ran out of it and completely forgot about getting a treat. :graduated:

According to my counters, about 1000 people went through this year.

Next year we are seriously concidering moving it out of the garage and into a big pole barn, maybe even charging money. :o

Thanks again for the help!

-Scott

For next year: Ratting a floppy disk drive for animation is fairly easy. Disassemble the threaded portion that moves the heads back and forth and hook a string to that. Leave the floppy connected and when you access it it will attempt to seek to track zero and wind the string up, moving whatever you have connected to that . For move oomph, try one of the older style 5 1/4" drives. Even the drive motor can have a piece of cardboard or plastic attached to it that can be used to make a flapping noise.

Use your imagination and experiment. Even new floppy drives are so cheap these days and you already have the interface, driver electronics and power supply connected - no rummaging around for servos, robotic parts, custom software, etc. The floppy interface supports two drives, and a lot of floppy cables still have connectors for two drives present.

The code portion to try and access Drive A: and B: from AutoIT and play sounds from the sound card on cue shouldn't be too hard. You've got twelve months to experiment...

Good luck! B)

Link to comment
Share on other sites

For next year: Ratting a floppy disk drive for animation is fairly easy. Disassemble the threaded portion that moves the heads back and forth and hook a string to that. Leave the floppy connected and when you access it it will attempt to seek to track zero and wind the string up, moving whatever you have connected to that . For move oomph, try one of the older style 5 1/4" drives. Even the drive motor can have a piece of cardboard or plastic attached to it that can be used to make a flapping noise.

Use your imagination and experiment. Even new floppy drives are so cheap these days and you already have the interface, driver electronics and power supply connected - no rummaging around for servos, robotic parts, custom software, etc. The floppy interface supports two drives, and a lot of floppy cables still have connectors for two drives present.

The code portion to try and access Drive A: and B: from AutoIT and play sounds from the sound card on cue shouldn't be too hard. You've got twelve months to experiment...

Good luck! B)

Good ideas!

I get many of my motors and such from old printers, scanners and fax machines. I use geared AC motors from old microwaves (ones used to rotate the tray or, on really old microwaves, the motor that rotated the HF deflector on the top) and mount them to the ceiling with an arm attached to pull fish line and make things move. I have a bunch of motion dectors and pressure sensitive mats from and old alarm company that went out of business. Black lights, and strobe lights that I've collected over the years, a few from hotel fire alarm signalers... shhh!

Here's a few videos I made of the things in action...

The bearings were about shot on this one, video was taken at the end of the night.

http://www.paintingbynrs.com/halloween/skeleton.mpg

Cyborg Chick, the head movement broke at some point during the night.

http://www.paintingbynrs.com/halloween/cyborgchick_broke.mpg

Cyborg Chick the next day, fixed (a wire that sensed the knife chop broke).

http://www.paintingbynrs.com/halloween/cyborgchick_fixed.mpg

The back where all the controls are and the counter that counted once for each cycle of the skeleton.

4 people at a time went in so we had about 980 people total go through.

http://www.paintingbynrs.com/halloween/245_times4.mpg

One thing I need for next year is a bigger PLC, I ran out of outputs.

-Scott

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