Modifyer Keys

BlitzMax Forums/BlitzMax Beginners Area/Modifyer Keys

KrayzBlu(Posted 2005) [#1]
Hi, I can't seem to get my keyboard to register any of the modifyer keys. (Eg shift, command, control etc.) I have a generic Apple Extended USB Keyboard, and am using the "GetChar()" command.

Help Anyone?

Thanks,
KrayzBlu


Perturbatio(Posted 2005) [#2]
GetChar() returns ASCII codes only, is there a reason you are using that over Keydown() or KeyHit()?


KrayzBlu(Posted 2005) [#3]
I am using keyhit and keydown, however they don't seem to return anything for those keys. I was just using GetChar to see if the keys were registering


Perturbatio(Posted 2005) [#4]
does this work?

Graphics 640,480,0,0

While Not KeyDown(KEY_ESCAPE)
	Cls
	
	If KeyDown(KEY_LSHIFT) Then DrawText("Left Shift Pressed",0,0)
	
	Flip
Wend
End




KrayzBlu(Posted 2005) [#5]
yeah lshift and rshift works, but the modifier doesnt, neither do any other modifiers :/


Perturbatio(Posted 2005) [#6]
I think the MODIFIER consts are only for GUI events.


KrayzBlu(Posted 2005) [#7]
?
Does that mean there's no way to use them in my game?
:(


Perturbatio(Posted 2005) [#8]
Do you need to if you can use Keydown?


KrayzBlu(Posted 2005) [#9]
It would be kinda nice to have command/control - q to quit :)


Perturbatio(Posted 2005) [#10]
if Keydown(KEY_CTRL) and Keydown(KEY_Q) then end



KrayzBlu(Posted 2005) [#11]
Yeah, but like I was saying... My system dosnt recognize KEY_CTRL


Perturbatio(Posted 2005) [#12]
ah right, yep, ok.
in which case, you could do:
SuperStrict

Graphics 640,480,0,0

Global Quit:Int = False


While Not Quit
	Cls
		UpdateEvents()
	Flip
Wend

End

Function UpdateEvents()
	PollEvent()
	Select EventID()
		Case EVENT_KEYDOWN
			If EventData() = KEY_Q And EventMods() = MODIFIER_CONTROL Then 'MODIFIER_OPTION 
				Quit = True
			EndIf
	End Select
End Function





Yan(Posted 2005) [#13]
Erm...KEY_LCONTROL / KEY_RCONTROL (162/163)...Surely?

Try this...
Graphics 400, 300, 0

Repeat
	For c=1 To 192
		If KeyHit(c)
			If c = 27 Then End
			Cls
			DrawText "Keyhit = " + c, 10, 10
			Flip
		EndIf 
	Next
Forever



KrayzBlu(Posted 2005) [#14]
:D
Thanks for all your help Perturbatio, but your stuff didn't work :/
YanCanCode's idea worked, thanks man! I can't beleive I didn't think of that.

Thanks again,
KrayzBlu


marksibly(Posted 2005) [#15]
Graphics 640,480

While Not AppTerminate() Or Not Confirm( "Quit?" )
	Cls
	DrawText "Quit me!",0,0
	Flip
Wend



bubbz(Posted 2006) [#16]
This appears to be the closest thread to my current problem. I'm using maxgui and want a gui button to behave differently if shift or ctrl is held down. Perturbatio's code above appears to have the same problem, here's a slightly modified one to try:

SuperStrict

Graphics 640,480,0,0

Global Quit:Int = False


While Not Quit
		UpdateEvents()
Wend

End

Function UpdateEvents()
	WaitEvent()
	Select EventID()
		Case EVENT_KEYDOWN
			Cls
			DrawText("Eventdata="+EventData()+", EventMods()="+EventMods(),0,0)
			Flip
			If EventData() = KEY_Q And EventMods() = MODIFIER_CONTROL Then 'MODIFIER_OPTION 
				Quit = True
			EndIf
	End Select
End Function


Pressing ctrl or shift triggers it's own event, but then pressing another key whilst still holding ctrl or shift only shows the new keypress, and EventMods() remains zero. Unless i've badly interpreted the doc's, surely EventMods() should display another value depending on which modifier key is held?

I'm sure somebody can solve this easily... Thanks....


bubbz(Posted 2006) [#17]
I'm still having issues with this, is it possible there is a bug related to EVENT_GADGETACTION and EventMods()? Here's some basic MaxGUI code I tested:

'quick gui test of eventmods()
'displays the eventmods() value each time the gui button is pressed
'but always displays zero, even with control or shift held down

Strict

Global window:tgadget=CreateWindow("test window",10,10,320,240)
Global button:tgadget=CreateButton("press me",20,20,280,50,window)
Global label:tgadget=CreateLabel("EVENT_GADGETACTION EventMods()=?",20,80,280,30,window)

Repeat

	WaitEvent()
	
	Select EventID()
	
		Case EVENT_GADGETACTION
		
				SetGadgetText(label,"EVENT_GADGETACTION EventMods()="+EventMods())
			
        Case EVENT_WINDOWCLOSE

            End

        Case EVENT_APPTERMINATE

            End
	
	EndSelect
	
Forever


Could somebody else test this and/or get it working? Thank you.


Dreamora(Posted 2006) [#18]
No
EventMods, from what I remember, is only filled on EVENT_HOTKEYHIT with modifier keys, where it is used for modifier + someKey input handling.

If you want to use it otherwise, you have to check if KEY_LCONTROL, KEY_RCONTROL, KEYLALT etc are down when clicking it.


bubbz(Posted 2006) [#19]
Dreamora: thanks for the reply.

Next question: how can I check if KEY_LCONTROL (or any other) is down when the gui button is pressed? Didn't I read somewhere that KeyDown() and KeyHit() don't work in gui mode, as events are preferred?