dkl
Full Member
Posts: 234
|
Post by dkl on Jun 2, 2021 22:16:51 GMT -5
Can one get LB to simulate keyboard or mouse actions such as, Click Left/Middle/Right Mouse Button Ctrl +V to paste Ctrl+C to copy Ctrl+s to save etc....... I know AHK can do this, but wondered if one can do it from within LB?
|
|
|
Post by Stefan Pendl on Jun 3, 2021 3:17:56 GMT -5
See the code at Program to test LB5 as an example. The sub keybdEvent contains the code to send keyboard events.
|
|
|
Post by Rod on Jun 3, 2021 3:26:59 GMT -5
Search the forum for "keybd_event" for other examples. While you can easily simulate key presses the trick is having them act on the application you expect. They generally act on the application that has focus. You will need to tell us more about what you are trying to send keystrokes to.
|
|
|
Post by Walt Decker on Jun 3, 2021 9:59:44 GMT -5
You can simulate just about everything by using the sendmessage() api with the appropriate control handle and message. For edit controls the messages begin with EM For buttons the the messages begin with BM For listboxes the messages begin with LB For comboboxes the messages begin with CB For radio and check buttons you can send the get/setcheckstate messages to determine or set their state, i. e., checked, unchecked, indeterminate.
To set the focus to a control you can send the setfocus(control handle) api message. To activate a window you can send the WM_ACTIVATE message via sendmessage(). To bring a window to the foreground you can send the setforegroundwindow(window handle) message. To set the active window you can send the setactivewindow(window handle) message.
The key-presses you listed are menu accelerate keys. They can probably be simulated, but if I recall, it is a little tricky. I can do a little research to (possibly) come up with an answer.
|
|
|
Post by Walt Decker on Jun 3, 2021 13:39:25 GMT -5
Ok, for your accelerator keys, i. e. cut, copy, paste, look in help TEXTEDITOR link Text Command. That is the easy way. For other accelerator keys look at Sprites/TilesThe source code will give you an example of how to parse the menu to get what you want. Then, I think you can use sendmessage() with arguments WindowHndl, WM_COMMAND, wparam = hiword(BN_CLICKED), loword(MenuID), lparam = 0 e. g, CALLDLL #USER, "SendMessageA", WinHndl AS LONG, WM.COMMAND, wParam AS LONG, lParam AS LONG, RetVal AS VOID
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on Jun 3, 2021 23:00:15 GMT -5
Thanks Walt I'll read up on that. I only want to use a hotkey to run an AHK script. I was originally going to try to do everything I've done in the script using LB, but I've got the AHK script running , so I'll just use a Hotkey to start the script, but would like to auto run it from LB.
|
|