Suddenly had to finish the old project and ran into problem with keyboard input handling. I have a window with a list of items. I want to select an item by pressing the first few letters of its name on the keyboard, as it works in the Windows. Search on the Internet, unfortunately, did not give results.
I have this code for processing messages and events.
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_BN_CLICKED(IDHELP, OnHelp)
ON_WM_SIZE()
END_MESSAGE_MAP()
BEGIN_EVENTSINK_MAP(CMyDialog, CDialog)
ON_EVENT(CMyDialog, SOME_ID, SOME_DISP_ID, SomeFunction, SOME_PARAMS)
END_EVENTSINK_MAP()
I would like to know if it is possible to add such functionality to it.
I would appreciate any help.
Related
I have a virtual keyboard and I am trying to figure out a way to detect the user swiping keys, ie, pressing one winapi button control down (for eg 'Q') then moving the mouse/finger around over other keys to type out words. For a better description see the below image.
Currently the only solution I can think of is detect a WM_LBUTTONDOWN on a button. Then detect WM_MOUSEMOVE events over other buttons (by hit testing?) and record that key. When I next receive a WM_LBUTTONUP I know the user is finished typing. I've also tried to detect WM_TOUCH and WM_TOUCHHITTESTING events but on a Surface Pro 3 these events are not firing but this could be I need to register for these events?
Is there an existing WinAPI function/methodology I could use that I am unaware of?
I have a system with no keyboard. I can connect a keyboard, but ultimately the inputs come from a custom keypad which is not a HID device, it sends serial data which I can interpret and decode to determine if the user pressed Up, Down, Left, Right, or Enter.
Right now all I have is a Fl_Window, with two Fl_Button widgets. Focus is set for one of the buttons and callbacks are defined for these buttons. I know that if I attach a real keyboard, and use the arrow keys I can change focus from button to button. I do have to hit SPACE to activate a button.
My problem is determining how to cause these key presses using code when I decode the outcome form the embedded key pad. Because in deployment, there will be no actual keyboard.
What I've tried is to invoke int Fl_Window::handle(int) and not really had success. I've also tried to invoke int Fl::handle(int, Fl_Window *) and not had success.
Here are code examples:
if((ret = Fl::handle(FL_Left, window)) == 0)
That compiles, but I find that I get zero back, implying that it did not process the event.
if((ret = Fl_Window::handle(FL_Right)) == 0)
That does not compile, informing me that it "cannot call member function virtual int Fl_Window::handle(int) without object"
I'm thinking that the "int event" actually ought to be FL_KEYDOWN.
That logic leaves me to wonder though how I "set" event_key(). For instance, there are API functions to get that when one has a handler, but I do not wish to get that; I wish to cause that event to occur.
Is my only option here to figure out how to emulate a HID or make some type of virtual HID where I then cause the keyboard events to occur?
I do not feel I require a handler function in my application, I'm fine with the default behaviors which occur and cause my callback functions to be invoked. My problem is that I can't "cause" these events to occur.
You need to assign the desired key to e_keysym, then dispatch a FL_KEYDOWN event using Fl::handle_(). (Fl::handle() will not generate the followup FL_SHORTCUT event.)
Fl::e_keysym = FL_Left;
Fl::handle_(FL_KEYDOWN, window);
// sleep() and/or Fl::wait() as appropriate
Fl::handle_(FL_KEYUP, window);
In order to block ALL keyboard access, mouse access and keyboard shortcut events in one of my projects, I:
Created a full screen transparent borderless window, in front of other windows, but invisible.
Handle all keyboard and mouse events with simple return; the window itself.
Make the window modal [NSApp runModalForWindow:myWindow] in order to block keyboard shortcuts.
Release window from touchpad's gesture events only.
But this guy made it look simple in a tiny app -MACIFIER:
How did he do it?
not really sure if this would be usable, but you could use the program hotkeynet (generally used for gaming, but I have had success using other methods) and map every single key/mouse action to do nothing. I did something similar by blocking access to a specific program with it in about 20-30 minutes.
not sure if it will help; but it might be the solution you need?
I believe you can use Quartz Event Services. In particular, have a look at CGEventTapCreate, and note the 4th parameter, which allows you to specify what kinds of events you'd like to intercept. The available kinds of events are listed in the CGEventType enum.
If you set your tap to be an active filter, returning NULL from the callback will delete the event.
I need to subclass a VB6 form so that if the user hits the [ALT] key while left clicking the title/caption bar, I can do something custom (show dialog box, file io, whatever).
So far, I have been able to do the subclassing in my NewWndProc() to correctly trap the WM_NCLBUTTONDOWN message when wParam = HTCAPTION, but I don't know how to trap the [ALT] key at the same time.
I have used the SPY utility a bit to check for messages, but I still can't solve this. Thanks for any help.
Update:
Looks like I may have to use mouse and keyboard hooks?
As it's not sent as part of the message. but you can call GetKeyState(VK_MENU) to get whether it's pressed or not.
I've ran into next mystic thing in Winapi/MFC, I have an edit box, contents of which I have to select on Tab, Lclick, Rclick, Mclick and so on.
The sort of obvious path is to handle the SETFOCUS message and call SetSel(0, -1), which should select all text. But it doesn't work!
What's wrong? I tried googling, everyone seems to override Lclilks or handle SetSel in parent windows, but this is wrong from encapsulation point of view, also multiple clicks (user wants to insert something in the middle of the text) will break, and so on.
Why isn't my approach working, I tried like 10 different ways, tried to trap all possible focus messages, looked up info on MSDN, but nothing works as expected.
Also, I need to recreate the carret on focus, which also doesn't seem to work.
SETFOCUS message gets trapped alright. If I add __asm int 3, it breaks every time.
It's the create carret and setsel that gets swallowed it seems.
Post the edit an EM_SETSEL while handling WM_SETFOCUS. The mouse input is probably processed after the focus switches. Or post a user message and on receiving create the caret and then do the selection.