ctrl command + canvas + menu
BlitzMax Forums/MaxGUI Module/ctrl command + canvas + menu
| ||
I have a window with a menu and some gadgets. The menu includes commands with fast combinations using modifier ctrl. For example, when you press ctrl + S - activated menu item "to save the map." Besides - there canvas graphics, which rendered gaming locations. Canvas handles the events associated with the click of the mouse when its various modifiers. For example - when you click ctrl + LMB - an attempt is made to allocate the tile under the mouse pointer. And at LMB with zero modifier - process starts scrolling game level (by dragging the mouse button held down). Everything is wonderful, but there is some error. by pressing ctrl + s - opens a dialog box in which you are asked to select a save file. After all the processes related to conservation - when you click on the canvas is considered that the active modifier ctrl, and instead to scroll the map - a process of selection of the sprite, if pressed ctrl + LMB, not just paint. This happens as long as the user deliberately clicks on ctrl, and then let him go to canvas "saw" the ctrl no longer depressed. I suspect the problem lies in the fact that canvas handles the click event by ctrl, but because of the ctrl is released only after open another window (a window for selecting save file) - for canvas lost event that the ctrl was released . I tried to solve the problem of a crutch - after a process of conservation - I have to manually create events for the canvas that the ctrl key is released, but it is not working. Team of adding such an event: PostEvent (CreateEvent (EVENT_KEYUP, itidlab.browserGameScenes.canvas, MODIFIER_COMMAND)) prompt decision? Can I somehow "clean off" active modifiers for the gadget? Why am I confident that the ctrl active only for the canvas? Because if you click on S without ctrl, then the team does not start with a quick combination ctrl + S. |
| ||
There is a command called FlushKeys that you could call after calling RequestDir or RequestFile. |
| ||
"There is a command called FlushKeys that you could call after calling RequestDir or RequestFile. " Case MPSaveAs itidlab.mapsquares.saveAs("") FlushKeys() Case MPLoad ItidLab.mapSquares.Load() FlushKeys() Case MPTestLoad ItidLab.mapSquares.testload() FlushKeys() does not work :-( "Why am I confident that the ctrl active only for the canvas? Because if you click on S without ctrl, then the team does not start with a quick combination ctrl + S. " At the program level the modifier is not activated. It is activated for a particular gadget (to the canvas). So I guess. |
| ||
Can I simulate a key press? Is there such a command? Then I would have to simulate pressing CTRL after RequestFile. |
| ||
My knowledge of English is not possible to find this information. So I apologize for such possibly stupid questions. |
| ||
Are you using EventMods or KeyDown functions to test for the state of the control key? |
| ||
Import MaxGui.Drivers Strict Local test:ttest = New ttest.Create() While WaitEvent() test.event(CurrentEvent) Wend Type TTest Field window:TGadget Field menu:tgadget Field canvas:tgadget Method Create:TTest() window = CreateWindow("window", 0, 0, 500, 500) menu = CreateMenu("save", 0, WindowMenu(window), KEY_S, MODIFIER_COMMAND) UpdateWindowMenu(window) canvas = CreateCanvas(0, 0, ClientWidth(window), ClientHeight(window), window) SetGadgetLayout(canvas, True , True, True, True) SetGadgetSensitivity(canvas, SENSITIZE_ALL) Return Self End Method Method event(ev:TEvent) Select ev.source Case canvas If ev.id = EVENT_MOUSEDOWN Then If ev.mods = MODIFIER_COMMAND Then Print "Use Ctrl!" EndIf Case menu RequestFile("Select any file") Case window If ev.id = EVENT_WINDOWCLOSE Then End EndSelect End Method End Type |
| ||
I tried debugging win32maxguiex but im not familiar with it enough to figure where it should ignore hotkey events... But as a quick fix you can send a keyboard event that simulates a keyup right after RequestFile(). Extern "Win32" Const KEYEVENTF_EXTENDEDKEY:Int = $0001 Const KEYEVENTF_KEYUP:Int = $0002 Const KEYEVENTF_UNICODE:Int = $0004 Const KEYEVENTF_SCANCODE:Int = $0008 Function keybd_event( vk:Byte, scan:Byte, flags:Int, extra:Byte Ptr) EndExtern '----- call this right after RequestDialog() ----- keybd_event( VK_CONTROL, 0, KEYEVENTF_KEYUP, Null) |
| ||
I'm not sure if this will work, I don't have MinGW installed to test it. In the Win32MaxGUIEx.bmx module file, try replacing all occurrences of "GetKeyState" with "GetAsyncKeyState". Then rebuild the module. To restore the changes you just have to replace all occurrences of GetAsyncKeyState back to GetKeyState. EDIT: You may need to add this extern to that BMX file to use that function: Extern "Win32" Function GetAsyncKeyState:Short( vKey:Int ) End Extern |
| ||
In the Win32MaxGUIEx.bmx module file, try replacing all occurrences of "GetKeyState" with "GetAsyncKeyState". I actually tried that before my post, and it didnt do anything different.I have dug a bit more into it, and it doesnt look to be a problem with the input queue or event system. Looks more like modifiers are stored in some global place and used again. The reason i believe this is because EVERY message sent to the canvas has modifiers set! |
| ||
The simple fix is to use the Control key for mouse modes and Alt key for menu shortcuts and don't mix the two. |
| ||
I think that's going against established shortcuts. CTRL + Z (undo); CTRL + C, CTRL + V (clipboard); CTRL + O (open a file); I have dug a bit more into it, and it doesnt look to be a problem with the input queue or event system. Looks more like modifiers are stored in some global place and used again. The reason i believe this is because EVERY message sent to the canvas has modifiers set! Are you saying that the problem is generated outside of the BlitzMax scope? EDIT: Given Fillip's answer below, you think the problem happens in some place of the modules that were outside your investigation. |
| ||
The simple fix is to use the Control key for mouse modes and Alt key for menu shortcuts and don't mix the two. This variant does not suit me, as for mouse use all modifiers (for different purposes) I tried debugging win32maxguiex but im not familiar with it enough to figure where it should ignore hotkey events... But as a quick fix you can send a keyboard event that simulates a keyup right after RequestFile(). Thank you! That helped. Thank you and all those who participated in the topic. |
| ||
It would be nice to get to the bottom of this problem. I am not currently on Windows but I am curious if the endPanel code in system.win32.c is at fault. The call to SetFocus may have been added when the bbSystemRequestFile command used to set of.hwndOwner to 0 / Desktop. Now it is set (in theory) to the window that contains the Menu I am wondering if this is no longer needed and perhaps the root cause of this issue. |