keypress issue
BlitzPlus Forums/BlitzPlus Programming/keypress issue
| ||
I want the spacebar to "continue" the program loop. There are buttons to define various actions in the program. But when a button has been pressed, and is "highlighted" with the dotted rectangle, thereafter spacebar merely activates that button. I tried assigning the spacebar to a hotkeyevent, but there was no difference. I made a little test program to post, can anyone tell me where I am going wrong? thanks. Window=CreateWindow("TEST",200,200,300,300,0,1);main window Canvas=CreateCanvas(10,250,280,20,Window);canvas for the text Panel = CreatePanel (10,50,120,300,Window,0);panel for the buttons SetGadgetLayout Panel,1,0,1,0 Button1 = CreateButton ("button 1",0,0,120,30,Panel,1) Button2 = CreateButton ("button 2",0,50,120,30,Panel,1) ProgramOn= True SetBuffer CanvasBuffer(Canvas) PressCount% = 0 Button1Count% = 0 Button2Count% = 0 MyString$ = "waiting" While ProgramOn = True Color 0,0,0 Rect 0,0,280,20 Color 255,255,255 Text 5,3,MyString$ FlipCanvas Canvas Continue = False While Continue = False Select WaitEvent() Case $803 ProgramOn = False Continue = True Case $401 Select EventSource() Case Button1 Continue = True Button1Count% = Button1Count%+1 MyString$ = "Button 1 clicked "+Str(Button1Count%)+" times" Case Button2 Continue = True Button2Count% = Button2Count%+1 MyString$ = "Button 2 clicked "+Str(Button2Count%)+" times" End Select Case $101 If EventData() = 57 Then Continue = True PressCount% = PressCount%+1 MyString$ = "spacebar pressed "+Str(PressCount%)+" times" EndIf End Select Wend Wend End |
| ||
Use ActivateGadget window to pass the 'focus' back to the main window after the buttons are clicked. In the code below I have placed this call at the end of the 'Case $401' gadget hit check: Window=CreateWindow("TEST",200,200,300,300,0,1);main window Canvas=CreateCanvas(10,250,280,20,Window);canvas for the text Panel = CreatePanel (10,50,120,300,Window,0);panel for the buttons SetGadgetLayout Panel,1,0,1,0 Button1 = CreateButton ("button 1",0,0,120,30,Panel,1) Button2 = CreateButton ("button 2",0,50,120,30,Panel,1) ProgramOn= True SetBuffer CanvasBuffer(Canvas) PressCount% = 0 Button1Count% = 0 Button2Count% = 0 MyString$ = "waiting" While ProgramOn = True Color 0,0,0 Rect 0,0,280,20 Color 255,255,255 Text 5,3,MyString$ FlipCanvas Canvas Continue = False While Continue = False Select WaitEvent() Case $803 ProgramOn = False Continue = True Case $401 ; gadget hit Select EventSource() Case Button1 Continue = True Button1Count% = Button1Count%+1 MyString$ = "Button 1 clicked "+Str(Button1Count%)+" times" Case Button2 Continue = True Button2Count% = Button2Count%+1 MyString$ = "Button 2 clicked "+Str(Button2Count%)+" times" End Select ActivateGadget Window ; give 'focus' to window Case $101 If EventData() = 57 Continue = True PressCount% = PressCount%+1 MyString$ = "spacebar pressed "+Str(PressCount%)+" times" EndIf End Select Wend Wend End |
| ||
thank you Syntax its a charm :) |