Modifyer Keys
BlitzMax Forums/BlitzMax Beginners Area/Modifyer Keys
| ||
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 |
| ||
GetChar() returns ASCII codes only, is there a reason you are using that over Keydown() or KeyHit()? |
| ||
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 |
| ||
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 |
| ||
yeah lshift and rshift works, but the modifier doesnt, neither do any other modifiers :/ |
| ||
I think the MODIFIER consts are only for GUI events. |
| ||
? Does that mean there's no way to use them in my game? :( |
| ||
Do you need to if you can use Keydown? |
| ||
It would be kinda nice to have command/control - q to quit :) |
| ||
if Keydown(KEY_CTRL) and Keydown(KEY_Q) then end |
| ||
Yeah, but like I was saying... My system dosnt recognize KEY_CTRL |
| ||
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 |
| ||
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 |
| ||
: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 |
| ||
Graphics 640,480 While Not AppTerminate() Or Not Confirm( "Quit?" ) Cls DrawText "Quit me!",0,0 Flip Wend |
| ||
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.... |
| ||
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. |
| ||
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. |
| ||
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? |