Sign in to follow this  
Followers 0
datkewlguy

Musical Keyboard

7 posts in this topic

heres the code, the instructions are built into the program:

#include <GUIConstants.au3>

$mute = 0

$w = 300
$h = 250
$l = (@DesktopWidth - $w) / 2
$t = (@DesktopHeight - $h)
$win = "musical keyboard" 

$gui = GUICreate($win, $w, $h, $l, $h, $WS_MINIMIZEBOX + $WS_SYSMENU)
$edit = GUICtrlCreateEdit("", 0, 0, $w - 5, $h - 51, $ES_WANTRETURN + $ES_MULTILINE + $WS_TABSTOP + $ES_AUTOVSCROLL + $ES_AUTOHSCROLL + $WS_VSCROLL + $WS_HSCROLL)
$playback = GUICtrlCreateButton("P l a y  B a c k", 0, $h - 51, ($w / 3) + 40, 20)
$previewctrl = GUICtrlCreateButton("Preview: ON", 153, $h - 51, ($w / 3) + 42, 20)

GUICtrlSetData($edit, "New users: Please press F10 now, press F11 to clear.")

GUISetState()

GUISetBkColor("0xFFFFFF", $gui)

GUICtrlSetState($edit, $GUI_FOCUS)

WinSetOnTop($win, "", 1)

HotKeySet( "^!`", "play")
HotKeySet( "{ESC}", "myexit")

play()

Func play()
    HotKeySet( "^!`", "pause")
    
    While 1
        
        If WinActive($win) Then
            HotKeySet( "{F10}", "intro")
        Else
            HotKeySet( "{F10}")
        EndIf
        
        If WinActive($win) Then
            HotKeySet( "{F11}", "clear")
        Else
            HotKeySet( "{F11}")
        EndIf
        
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit

                
            Case $msg = $playback
                $sz_enc = GUICtrlRead($edit)
                For $i = 1 To StringLen($sz_enc)
                    $sz_tmptxt = ""
                    $sz_tmptxt = $sz_tmptxt & abcdef(StringMid($sz_enc, $i, 1))
                    Sleep(1)
                Next
                
                                
            Case $msg = $previewctrl
                                                
                If GUICtrlRead($previewctrl) = "Preview: ON"  Then
                    $mute = 1
                    GUICtrlSetData($previewctrl, "Preview: OFF")

                Else
                    $mute = 0       
                    GUICtrlSetData($previewctrl, "Preview: ON")

                EndIf           

            Case $mute = 0 And WinActive($win)
                If _IsPressed('5a') Then DllCall("kernel32.dll", "int", "Beep", "long", 212, "long", 150);z
                If _IsPressed('58') Then DllCall("kernel32.dll", "int", "Beep", "long", 225, "long", 150);x
                If _IsPressed('43') Then DllCall("kernel32.dll", "int", "Beep", "long", 238, "long", 150);c
                If _IsPressed('56') Then DllCall("kernel32.dll", "int", "Beep", "long", 253, "long", 150);v
                If _IsPressed('42') Then DllCall("kernel32.dll", "int", "Beep", "long", 268, "long", 150);b
                If _IsPressed('4E') Then DllCall("kernel32.dll", "int", "Beep", "long", 283, "long", 150);n
                If _IsPressed('4D') Then DllCall("kernel32.dll", "int", "Beep", "long", 300, "long", 150);m
                If _IsPressed('41') Then DllCall("kernel32.dll", "int", "Beep", "long", 318, "long", 150);a
                If _IsPressed('53') Then DllCall("kernel32.dll", "int", "Beep", "long", 337, "long", 150);s
                If _IsPressed('44') Then DllCall("kernel32.dll", "int", "Beep", "long", 357, "long", 150);d
                If _IsPressed('46') Then DllCall("kernel32.dll", "int", "Beep", "long", 378, "long", 150);f
                If _IsPressed('47') Then DllCall("kernel32.dll", "int", "Beep", "long", 401, "long", 150);g
                If _IsPressed('48') Then DllCall("kernel32.dll", "int", "Beep", "long", 425, "long", 150);h
                If _IsPressed('4a') Then DllCall("kernel32.dll", "int", "Beep", "long", 450, "long", 150);j
                If _IsPressed('4b') Then DllCall("kernel32.dll", "int", "Beep", "long", 477, "long", 150);k
                If _IsPressed('4c') Then DllCall("kernel32.dll", "int", "Beep", "long", 505, "long", 150);l
                If _IsPressed('51') Then DllCall("kernel32.dll", "int", "Beep", "long", 535, "long", 150);q
                If _IsPressed('57') Then DllCall("kernel32.dll", "int", "Beep", "long", 567, "long", 150);w
                If _IsPressed('45') Then DllCall("kernel32.dll", "int", "Beep", "long", 601, "long", 150);e
                If _IsPressed('52') Then DllCall("kernel32.dll", "int", "Beep", "long", 636, "long", 150);r
                If _IsPressed('54') Then DllCall("kernel32.dll", "int", "Beep", "long", 674, "long", 150);t
                If _IsPressed('59') Then DllCall("kernel32.dll", "int", "Beep", "long", 714, "long", 150);y
                If _IsPressed('55') Then DllCall("kernel32.dll", "int", "Beep", "long", 757, "long", 150);u
                If _IsPressed('49') Then DllCall("kernel32.dll", "int", "Beep", "long", 802, "long", 150);i
                If _IsPressed('4f') Then DllCall("kernel32.dll", "int", "Beep", "long", 849, "long", 150);o
                If _IsPressed('50') Then DllCall("kernel32.dll", "int", "Beep", "long", 925, "long", 150);p                 
    
                
        EndSelect
    WEnd
    
EndFunc  ;==>play

Func pause()
    HotKeySet( "^!`", "play")
EndFunc  ;==>pause

Func abcdef($sz_t)
    If StringIsUpper($sz_t) Then
        
        If $sz_t = "a"  Then DllCall("kernel32.dll", "int", "Beep", "long", 318, "long", 200)
        If $sz_t = "b"  Then DllCall("kernel32.dll", "int", "Beep", "long", 268, "long", 200)
        If $sz_t = "c"  Then DllCall("kernel32.dll", "int", "Beep", "long", 238, "long", 200)
        If $sz_t = "d"  Then DllCall("kernel32.dll", "int", "Beep", "long", 357, "long", 200)
        If $sz_t = "e"  Then DllCall("kernel32.dll", "int", "Beep", "long", 601, "long", 200)
        If $sz_t = "f"  Then DllCall("kernel32.dll", "int", "Beep", "long", 378, "long", 200)
        If $sz_t = "g"  Then DllCall("kernel32.dll", "int", "Beep", "long", 401, "long", 200)
        If $sz_t = "h"  Then DllCall("kernel32.dll", "int", "Beep", "long", 425, "long", 200)
        If $sz_t = "i"  Then DllCall("kernel32.dll", "int", "Beep", "long", 802, "long", 200)
        If $sz_t = "j"  Then DllCall("kernel32.dll", "int", "Beep", "long", 450, "long", 200)
        If $sz_t = "k"  Then DllCall("kernel32.dll", "int", "Beep", "long", 477, "long", 200)
        If $sz_t = "l"  Then DllCall("kernel32.dll", "int", "Beep", "long", 505, "long", 200)
        If $sz_t = "m"  Then DllCall("kernel32.dll", "int", "Beep", "long", 300, "long", 200)
        If $sz_t = "o"  Then DllCall("kernel32.dll", "int", "Beep", "long", 849, "long", 200)
        If $sz_t = "n"  Then DllCall("kernel32.dll", "int", "Beep", "long", 283, "long", 200)
        If $sz_t = "p"  Then DllCall("kernel32.dll", "int", "Beep", "long", 925, "long", 200)
        If $sz_t = "q"  Then DllCall("kernel32.dll", "int", "Beep", "long", 535, "long", 200)
        If $sz_t = "r"  Then DllCall("kernel32.dll", "int", "Beep", "long", 636, "long", 200)
        If $sz_t = "s"  Then DllCall("kernel32.dll", "int", "Beep", "long", 337, "long", 200)
        If $sz_t = "t"  Then DllCall("kernel32.dll", "int", "Beep", "long", 674, "long", 200)
        If $sz_t = "u"  Then DllCall("kernel32.dll", "int", "Beep", "long", 757, "long", 200)
        If $sz_t = "v"  Then DllCall("kernel32.dll", "int", "Beep", "long", 253, "long", 200)
        If $sz_t = "w"  Then DllCall("kernel32.dll", "int", "Beep", "long", 567, "long", 200)
        If $sz_t = "x"  Then DllCall("kernel32.dll", "int", "Beep", "long", 225, "long", 200)
        If $sz_t = "y"  Then DllCall("kernel32.dll", "int", "Beep", "long", 714, "long", 200)
        If $sz_t = "z"  Then DllCall("kernel32.dll", "int", "Beep", "long", 212, "long", 200)
        
    EndIf
    If $sz_t = "a"  Then DllCall("kernel32.dll", "int", "Beep", "long", 318, "long", 150)
    If $sz_t = "b"  Then DllCall("kernel32.dll", "int", "Beep", "long", 268, "long", 150)
    If $sz_t = "c"  Then DllCall("kernel32.dll", "int", "Beep", "long", 238, "long", 150)
    If $sz_t = "d"  Then DllCall("kernel32.dll", "int", "Beep", "long", 357, "long", 150)
    If $sz_t = "e"  Then DllCall("kernel32.dll", "int", "Beep", "long", 601, "long", 150)
    If $sz_t = "f"  Then DllCall("kernel32.dll", "int", "Beep", "long", 378, "long", 150)
    If $sz_t = "g"  Then DllCall("kernel32.dll", "int", "Beep", "long", 401, "long", 150)
    If $sz_t = "h"  Then DllCall("kernel32.dll", "int", "Beep", "long", 425, "long", 150)
    If $sz_t = "i"  Then DllCall("kernel32.dll", "int", "Beep", "long", 802, "long", 150)
    If $sz_t = "j"  Then DllCall("kernel32.dll", "int", "Beep", "long", 450, "long", 150)
    If $sz_t = "k"  Then DllCall("kernel32.dll", "int", "Beep", "long", 477, "long", 150)
    If $sz_t = "l"  Then DllCall("kernel32.dll", "int", "Beep", "long", 505, "long", 150)
    If $sz_t = "m"  Then DllCall("kernel32.dll", "int", "Beep", "long", 300, "long", 150)
    If $sz_t = "o"  Then DllCall("kernel32.dll", "int", "Beep", "long", 849, "long", 150)
    If $sz_t = "n"  Then DllCall("kernel32.dll", "int", "Beep", "long", 283, "long", 150)
    If $sz_t = "p"  Then DllCall("kernel32.dll", "int", "Beep", "long", 925, "long", 150)
    If $sz_t = "q"  Then DllCall("kernel32.dll", "int", "Beep", "long", 535, "long", 150)
    If $sz_t = "r"  Then DllCall("kernel32.dll", "int", "Beep", "long", 636, "long", 150)
    If $sz_t = "s"  Then DllCall("kernel32.dll", "int", "Beep", "long", 337, "long", 150)
    If $sz_t = "t"  Then DllCall("kernel32.dll", "int", "Beep", "long", 674, "long", 150)
    If $sz_t = "u"  Then DllCall("kernel32.dll", "int", "Beep", "long", 757, "long", 150)
    If $sz_t = "v"  Then DllCall("kernel32.dll", "int", "Beep", "long", 253, "long", 150)
    If $sz_t = "w"  Then DllCall("kernel32.dll", "int", "Beep", "long", 567, "long", 150)
    If $sz_t = "x"  Then DllCall("kernel32.dll", "int", "Beep", "long", 225, "long", 150)
    If $sz_t = "y"  Then DllCall("kernel32.dll", "int", "Beep", "long", 714, "long", 150)
    If $sz_t = "z"  Then DllCall("kernel32.dll", "int", "Beep", "long", 212, "long", 150)
    
    If $sz_t = "1"  Then Sleep(10)
    If $sz_t = "2"  Then Sleep(20)
    If $sz_t = "3"  Then Sleep(30)
    If $sz_t = "4"  Then Sleep(40)
    If $sz_t = "5"  Then Sleep(50)
    If $sz_t = "6"  Then Sleep(60)
    If $sz_t = "7"  Then Sleep(70)
    If $sz_t = "8"  Then Sleep(80)
    If $sz_t = "9"  Then Sleep(90)
    
    Return $sz_t
EndFunc  ;==>abcdef

Func _IsPressed($hexKey)
; $hexKey must be the value of one of the keys.
; _IsPressed will return 0 if the key is not pressed, 1 if it is.
    
    Local $aR, $bRv;$hexKey
    $hexKey = '0x' & $hexKey
    $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
;If $aR[0] = -32767 Then
    If $aR[0] <> 0 Then
        $bRv = 1
    Else
        $bRv = 0
    EndIf
    
    Return $bRv
EndFunc  ;==>_IsPressed


Func myexit()
    Exit
EndFunc  ;==>myexit

Func intro()
    GUICtrlSetData($edit, "")
    GUICtrlSetData($edit, "Welcome to Musical Keys 1.0, this is the intro screen!" & @CRLF & "As you just learned, the intro screen can be accessed by pressing F10 When this window is active." & @CRLF & "Type letters into this field, unless you have clicked the mute button, a preview of the note you insert will be played through your sound card." & @CRLF & "If you do not have a soundcard that can play these noises correctly, this program will not work for you." & @CRLF & "Capital letters are played back as slightly longer, and rests vary in length from 1-9, you can use a combination of these rests to make an even longer rest." & @CRLF & "You are now ready to begin using Musical Keys, enjoy!")
EndFunc  ;==>intro

func clear()
    GUICtrlSetData($edit, "")
    endfunc

#cs
    a0   401    802   1604   1745
    a#0  378    757   1514   1647
    b0   357    714   1429   1555
    c0   337    674   1348   1468
    c#0  318    636   1273   1385
    d0   300    601   1201   1308
    d#0  283    567   1134   1234
    e0   268    535   1070   1165
    f0   253    505   1010   1100
    f#0  238    477 954   1038
    g0   225    450 900 980
    g#0  212    425 849 925
    
;---------------------------------
    
    41 A key
    42 B key
    43 C key
    44 D key
    45 E key
    46 F key
    47 G key
    48 H key
    49 I key
    4A J key
    4B K key
    4C L key
    4D M key
    4E N key
    4F O key
    50 P key
    51 Q key
    52 R key
    53 S key
    54 T key
    55 U key
    56 V key
    57 W key
    58 X key
    59 Y key
    5A Z key
    
#ce

If anyone has any improvements it'd be great to hear from you,

try putting this in and see what you get:

q4q4q55h4q54r999a

(im not that good with it yet but like all things it just takes practice...)

primarily im focused on making the rythems easier to do its kinda tricky at this point.

Thanks everyone...

Share this post


Link to post
Share on other sites



Cool, script. I been jamming out on the keyboard of like 5 mins. LOL :(

Very useful script too. I am making a game and I want to add some sounds to it. This script will help me alot. Thank you for all the hard work.


.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

cool, I think Larry made something similar to this a while back. Here's something i made to help another poster. Maybe they will provide some ideas. Check through the posts. I couldn't find Larry's post but here's the one i did:#68312

Edited by steveR

AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.

Share this post


Link to post
Share on other sites

yeah i origionally created this to find the notes i needed on the soundcard for stuff, it is fun to play with though lol. I hope you all like it but i know its pretty messy, which is why i'd appreciate improvement, thx.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I suggest you switch out the If's with Select's. That'll make it go (if I remember right) about 10% faster.

EDIT:

Very very cool :(

You should get the a few Mario songs on this :(

Edited by Insolence

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites

Cool, script. I been jamming out on the keyboard of like 5 mins. LOL :( 

Very useful script too. I am making a game and I want to add some sounds to it. This script will help me alot. Thank you for all the hard work.

<{POST_SNAPBACK}>

I got the new game finished("Simon Says") for now and I used your script to help me with the beeps in the game.

.

Share this post


Link to post
Share on other sites

Is there a way you can make it beep as long as you hold the button.... in stead of the little consecutive subdivided beeps?

Share this post


Link to post
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
Sign in to follow this  
Followers 0