CTRL + LeftClick
Posted: Wed Oct 30, 2013 12:19 am
Been on a very good run for the past few days but now I have hit a problem. It seems so simple, the solution must be right under my nose but I can't see it. Change of coffee brand made no difference at all.
All I want to do is this: When the User clicks a button, a value is set in a TextGadget (1). If the CTRL key is being held down at the time, a different value is set (100). Fail Snippet:
Edit: Really want it to work with CTRL. If the shortcut is tied to any 'regular' key, say 'Q', the above snippet works - Well, works-ish. Q + Button Click does insert the value '100'. Yet the next Button Click, withput holding Q down, should insert the value '1', but on the first click it does not - second click it does....
Edit2: This works, at the top of the loop (without PB shortcut): 
All I want to do is this: When the User clicks a button, a value is set in a TextGadget (1). If the CTRL key is being held down at the time, a different value is set (100). Fail Snippet:
Code: Select all
Enumeration
#Win
#Btn
#Txt
EndEnumeration
Procedure Win()
;-------------
If OpenWindow(#Win,0,0,150,150,"Win",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(#Txt, 50, 20, 50, 25, "0", #PB_Text_Center|#PB_Text_Border)
ButtonGadget(#Btn, 50, 70, 50, 50, "Btn")
AddKeyboardShortcut(#Win, #PB_Shortcut_Control, #Btn)
EndIf
EndProcedure
Win()
iVal = 1
Repeat
iEvent = WaitWindowEvent()
Select iEvent
Case #PB_Event_Menu: If(EventMenu() = #Btn) : iVal = 100 : EndIf
Case #PB_Event_Gadget
If(EventGadget() = #Btn)
SetGadgetText(#Txt,Str(iVal))
iVal = 1
EndIf
EndSelect
Until iEvent = #PB_Event_CloseWindow
EndEdit2: This works, at the top of the loop (without PB shortcut):
Code: Select all
If GetAsyncKeyState_(#VK_CONTROL | #Btn) : iVal = 100 : Else : iVal = 1 : EndIf