how to read a keypress AND a mouseclick?
BlitzPlus Forums/BlitzPlus Programming/how to read a keypress AND a mouseclick?
| ||
apparently in this code, I can't rightclick the canvas while holding down the left ctrl key. Do I have to use $101 here too? (since $101 and $203 have their own EventData()) Do I miss something? :) any suggestions?
app=CreateWindow("bla",100,100,256,256)
canvas=CreateCanvas(32,32,64,64,app)
; left ctrl= 29
Repeat
WaitEvent()
If EventSource()=app
If EventID()=$803 Exit
EndIf
If EventID()=$101 ; esc
If EventData()=1 Exit
EndIf
If EventSource()=canvas
If EventID()=$201 ; leftmousedown
If EventData()=1 Exit
EndIf
EndIf
If EventSource()=canvas
If EventID()=$201 And KeyDown(29); rightmousedown + left ctrl (?) <- uh??
If EventData()=3 Exit
EndIf
EndIf
Forever
End
|
| ||
| Uh, lads, I'm desperately waiting on suggestions :) Run this one, when you start it, press 'C' and you'll see it works.. now hit any button.. and then try to hit the 'C' again.. doesn't work here! Make sure the 16th button (requestfile) works.. I tried 'activategadget app' but this doesn't give me the result I want..
app=CreateWindow("keydown test",64,64,512,256)
Global canvas=CreateCanvas(32,32,160,160,app)
Global KEY=False
; bunch o' worthless buttons
Dim b(16)
For x=0 To 3:For y=0 To 3
b(ndx)=CreateButton(ndx,200+(x*24),32+(y*24),24,24,app)
ndx=ndx+1
Next:Next
b(16)=CreateButton(ndx,300,32,100,32,app)
SetBuffer CanvasBuffer(canvas)
Repeat
; some boring math here..
i=i+1
amp=60+Sin(i*10)*20
x=80+Sin(i+amp)*amp:y=80+Cos(i-amp)*amp
x=x Mod 160:y=y Mod 160
t=WaitEvent(8)
If t=0
UpdatePixel(x,y)
EndIf
;ActivateGadget app ; <- this doesn't work!!
; app close
If EventSource()=app
If EventID()=$803
Exit
EndIf
EndIf
; read key
If EventID()=$101
If EventData()=46
KEY=True ; "C"
EndIf
EndIf
If EventID()=$102
If EventData()=46
KEY=False ; "C"
EndIf
EndIf
If EventSource()=b(16)
crap$=RequestFile$("test","bla")
EndIf
Forever
FreeGadget app
End
Function UpdatePixel(x,y)
Cls
Rect x,y,3,3
Rect y,x,3,3
If KEY Text 2,2,"'C'"
FlipCanvas(canvas)
End Functionction
|
| ||
| CS, For the 'button clicked / keypress' problem see this post As for LCtrl+RMB this works: app=CreateWindow("bla",100,100,256,256)
canvas=CreateCanvas(32,32,64,64,app)
Const key_LCTRL=29
Global lctrl_flag=0
Repeat
WaitEvent
stat$=""
If EventSource()=app
If EventID()=$803 Exit
EndIf
If EventID()=$101 ; esc
If EventData()=1 Exit
lctrl_flag=(1 And EventData()=key_LCTRL)
EndIf
If EventID()=$102
lctrl_flag=(0 And EventData()=key_LCTRL)
EndIf
If EventSource()=canvas
If EventID()=$201 ; mouse buitton
If EventData()=1 Exit
If EventData()=2 ; right button
If lctrl_flag stat$="Left Control + RMB"
EndIf
EndIf
EndIf
SetStatusText app,stat$
Forever
End |