sandin Posted April 1, 2007 Share Posted April 1, 2007 I'm trying to make a virtual keyboard (like a piano), and the black keys needs to stay above white keys, so how can I make them (black keys) stay above? And is it posible to change the button's look? I wanna make them look like buttons in the VB, the old type, squared, with sharp edges. Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
SadBunny Posted April 1, 2007 Share Posted April 1, 2007 I'm trying to make a virtual keyboard (like a piano), and the black keys needs to stay above white keys, so how can I make them (black keys) stay above?And is it posible to change the button's look? I wanna make them look like buttons in the VB, the old type, squared, with sharp edges.Well, GuiCtrlCreateGraphic might be useful for creating the rectangles that represent the piano buttons. (You can customize their colors and such).But the catch is they can't overlap if you want to be able to click them, which might be a pain for a piano keyboard, since I guess you would want to first draw the white keys and then "overlappingly" draw the black keys over them (to make it look&feel more real). This will look nice (I tried it) but the thing is that it seems that since the white keys are drawn first, they will register even if you click on the black keys. Meaning that you will have to find some sort of workaround like defining the key areas and then calculating in which was clicked, or giving them all a slightly different color, or anything else by which you can distinguish the keys. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
SadBunny Posted April 1, 2007 Share Posted April 1, 2007 (edited) Well, GuiCtrlCreateGraphic might be useful for creating the rectangles that represent the piano buttons. (You can customize their colors and such). But the catch is they can't overlap if you want to be able to click them, which might be a pain for a piano keyboard, since I guess you would want to first draw the white keys and then "overlappingly" draw the black keys over them (to make it look&feel more real). This will look nice (I tried it) but the thing is that it seems that since the white keys are drawn first, they will register even if you click on the black keys. Meaning that you will have to find some sort of workaround like defining the key areas and then calculating in which was clicked, or giving them all a slightly different color, or anything else by which you can distinguish the keys. BTW this is what I came up with to create the gui for a very crude, simple piano. Is this what you sort-of meant it to be? #include <array.au3> HotKeySet("{ESC}","exiting") $mainGui = GUICreate("piano",400,300) Dim $key[13],$note[13] $whitekeys = _ArrayCreate(0,2,4,5,7,9,11,12) $blackkeys = _ArrayCreate(1,3,6,8,10) $keyNames = _ArrayCreate("C","#C","D","#D","E","F","#F","G","#G","A","#A","B","C") $counter = 0 For $x In $whitekeys $key[$x] = GUICtrlCreateGraphic(40+40*$counter,10,39,170) GUICtrlSetBkColor($key[$x],255+256*255+65536*255) $counter += 1 Next For $x In $blackkeys $key[$x] = GUICtrlCreateGraphic(45+40*$x/2+Int($x / 6)*20,10,30,100) GUICtrlSetBkColor($key[$x],0) Next GUISetState() While 1 Sleep(10) WEnd Func Exiting() Exit EndFunc Edited April 1, 2007 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
martin Posted April 1, 2007 Share Posted April 1, 2007 (edited) deleted because double posted Edited April 1, 2007 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted April 1, 2007 Share Posted April 1, 2007 Here is a way to get the sounds from SadBunny's post. The frequencies are just to get something to work, and you need to check for a mouse button press before playing the sound etc, but anyway this is just to demonstrate the idea. expandcollapse popup#include <array.au3> #include <GUIConstants.au3> #include <_ControlHover.au3> $mainGui = GUICreate("piano",400,300) Dim $key[13],$note[13] $whitekeys = _ArrayCreate(0,2,4,5,7,9,11,12) $blackkeys = _ArrayCreate(1,3,6,8,10) $keyNames = _ArrayCreate("C","#C","D","#D","E","F","#F","G","#G","A","#A","B","C") $Button_1 = GUICtrlCreateButton ("Button 1", 50, 30, 100, 20) $counter = 0 For $x In $whitekeys $key[$x] = GUICtrlCreateGraphic(40+40*$counter,10,39,170) GUICtrlSetBkColor($key[$x],255+256*255+65536*255) $counter += 1 Next For $x In $blackkeys $key[$x] = GUICtrlCreateGraphic(50+40*$x/2+Int($x / 6)*20,10,20,100) GUICtrlSetBkColor($key[$x],0) Next GUISetState() $dll = dllopen("user32.dll") While 1 $msg1 = GUIGetMsg() If $msg1 = $GUI_EVENT_CLOSE Then ExitLoop EndIf $w = WindowFromPoint() if $w = GUICtrlGetHandle($Button_1) then beep(600,40) for $dd = 0 to 12 $GuiHnd = GUICtrlGetHandle ($key[$dd]) if $w = $GuiHnd Then beep(200+10*$dd,30) EndIf Next WEnd dllclose($dll) Func WindowFromPoint() Local $point, $cHwnd, $hwnd, $pos, $size $point = MouseGetPos() $hwnd = DLLCall($dll, "hwnd", "WindowFromPoint", "int", $point[0], "int", $point[1]) If $hwnd[0] <> 0 Then $pos = WinGetPos($hwnd[0]) If @error Then Return 0 $size = WinGetClientSize($hwnd[0]) If @error Then Return 0 $pos[0] += (($pos[2] - $size[0]) / 2) $pos[1] += (($pos[3] - $size[1]) - (($pos[2] - $size[0]) / 2)) $cHwnd = DLLCall($dll,"hwnd","RealChildWindowFromPoint","hwnd",$hwnd[0], _ "int",$point[0] - $pos[0],"int",$point[1] - $pos[1]) If $cHwnd[0] <> 0 Then $hwnd[0] = $cHwnd[0] EndIf Return $hwnd[0] EndFunc Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted April 1, 2007 Share Posted April 1, 2007 That one didn't quite work. This one detects the black keys better. expandcollapse popup#include <array.au3> #include <GUIConstants.au3> #include <_ControlHover.au3> ;HotKeySet("{ESC}","exiting") $mainGui = GUICreate("piano",400,300) Dim $key[13],$note[13] $whitekeys = _ArrayCreate(0,2,4,5,7,9,11,12) $blackkeys = _ArrayCreate(1,3,6,8,10) $keyNames = _ArrayCreate("C","#C","D","#D","E","F","#F","G","#G","A","#A","B","C") $Button_1 = GUICtrlCreateButton ("Button 1", 50, 30, 100, 20) $counter = 0 For $x In $whitekeys $key[$x] = GUICtrlCreateGraphic(40+40*$counter,10,39,170) GUICtrlSetBkColor($key[$x],255+256*255+65536*255) $counter += 1 Next For $x In $blackkeys $key[$x] = GUICtrlCreateGraphic(50+40*$x/2+Int($x / 6)*20,10,20,100) GUICtrlSetBkColor($key[$x],0) Next for $dd = 0 to 12 _ControlHover(2, "", $key[$dd]) Next GUISetState() While 1 $msg1 = GUIGetMsg() If $msg1 = $GUI_EVENT_CLOSE Then ExitLoop EndIf $Over = _ControlHover(0, $mainGui) If $Over = 1 Then ;if $w = GUICtrlGetHandle($Button_1) then beep(600,40) for $dd = 0 to 12 If @extended = $key[$dd] then beep(200+10*$dd,30) guictrlsetdata($Button_1,$keyNames[$dd]) EndIf Next EndIf WEnd Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now