Hitting key on canvas: sound "NotAllowed" played

BlitzMax Forums/BlitzMax Programming/Hitting key on canvas: sound "NotAllowed" played

explosive(Posted 2008) [#1]
Hello verybody,
I am using a canvas to draw Text on the screen and I want the user to change it. Now when hitting a key the OS (at least on MacOS) plays the sound "NotAllowed" which can get quite annoying after a while. Is there a way to get rid of it? Can imagine that this might happen on WinVista and some of the newer Linux GUIs as well.

It might be easier to simply draw a TextArea but I had that the version before and I didn't like the style to have a mask and then draw the preview. I would appreciate if I can find a solution for typing directly to a canvas.

Thanks very much
Simon


William Drescher(Posted 2008) [#2]
Try putting a text area off the screen and when the user clicks on the canvas, put focus on the text area. The take the data from the text area and draw it to the canvas.
'Example code: DOES NOT WORK

Local Win:TGadget = CreateWindow("Blah",0,0,640,480)
Local HiddenBox:TGadget = CreateTextArea(1000,1000,0,0,Win)
Local DrawToCanvas:TGadget = CreateCanvas(0,0,640,480,Win)

Repeat
    WaitEvent()
    Select EventId()
        Case EVENT_MOUSEHIT
            ActivateGadget(HiddenBox)
            DrawCanvasCaret(MouseX(),MouseY())
        Case EVENT_GADGETACTION
            If EventSource() = HiddenBox Then
                DrawTextOnCanvas()
            EndIf
        Case EVENT_GADGETPAINT
            DrawTextOnCanvas()
            DrawCanvasCaret()
    EndSelect
Until EventId() = EVENT_WINDOWCLOSE
End

Function DrawCanvasCaret(X:Int, Y:Int)
    'Draw the caret at the mouse position
EndFunction

Function DrawTextOnCanvas()
    Local Txt:String = TextAreaText(HiddenBox)
    'Draw the data from "Txt" to the canvas
EndFunction
This is a VERY basic example but with a few improvements, this could be what you are looking for.

EDIT: Another note: Trap keystrokes (like left and right keys) so you can move the caret inside the canvas.