patrik2991 Posted June 7, 2010 Share Posted June 7, 2010 Is there a way, like send, controlsend, to "emulate" a button press with virtual key code?Virtual key codes(_IsPressed get these virtual key codes, if someone don't know) Link to comment Share on other sites More sharing options...
Zibit Posted June 7, 2010 Share Posted June 7, 2010 i think this has to work with memory... i have no idea how you could do this but i hope you do cuz this would be a whole new step to autoit. Creator Of Xtreme DevelopersPixel Pattern UDFTray GUI UDFMathssend & recive register scriptMouse Control via Webcam Link to comment Share on other sites More sharing options...
Zibit Posted June 7, 2010 Share Posted June 7, 2010 try to use dllcall... that might be the way. Creator Of Xtreme DevelopersPixel Pattern UDFTray GUI UDFMathssend & recive register scriptMouse Control via Webcam Link to comment Share on other sites More sharing options...
KaFu Posted June 7, 2010 Share Posted June 7, 2010 This post by Authenticity points in the direction you should go... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Yashied Posted June 7, 2010 Share Posted June 7, 2010 (edited) Sends 0x41 ("A") key. DllCall('user32.dll', 'int', 'keybd_event', 'int', 0x41, 'int', 0, 'int', 0, 'ptr', 0) DllCall('user32.dll', 'int', 'keybd_event', 'int', 0x41, 'int', 0, 'int', 2, 'ptr', 0) Edited June 7, 2010 by Yashied Norm73 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
socap Posted January 27, 2012 Share Posted January 27, 2012 Is there a more convenient way to send virtual keys? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 27, 2012 Moderators Share Posted January 27, 2012 socap, Just wrap those 2 lines in a function: _Send_Virtual_Key(0x41) Func _Send_Virtual_Key($iCode) If Not IsInt($iCode) Then Return DllCall('user32.dll', 'int', 'keybd_event', 'int', $iCode, 'int', 0, 'int', 0, 'ptr', 0) DllCall('user32.dll', 'int', 'keybd_event', 'int', $iCode, 'int', 0, 'int', 2, 'ptr', 0) EndFunc How much more convenient would you like it to be? M23 Norm73 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Blue_Drache Posted January 27, 2012 Share Posted January 27, 2012 Mmm.... spoonfed code is delicious! jaberwacky and TheXman 1 1 Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
Jonatas Posted October 29, 2019 Share Posted October 29, 2019 On 1/27/2012 at 12:26 PM, Melba23 said: socap, Just wrap those 2 lines in a function: _Send_Virtual_Key(0x41) Func _Send_Virtual_Key($iCode) If Not IsInt($iCode) Then Return DllCall('user32.dll', 'int', 'keybd_event', 'int', $iCode, 'int', 0, 'int', 0, 'ptr', 0) DllCall('user32.dll', 'int', 'keybd_event', 'int', $iCode, 'int', 0, 'int', 2, 'ptr', 0) EndFunc How much more convenient would you like it to be? M23 This works fine, but how can I direct to a specific window? Link to comment Share on other sites More sharing options...
Nine Posted October 30, 2019 Share Posted October 30, 2019 Depends on the application you are trying to send keys to : ControlSend is one way or _SendMessageA could work too. Otherwise, you will have to resort to put the application in foreground... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Jonatas Posted October 30, 2019 Share Posted October 30, 2019 Thanks for the quick reply Nine! Isn't there a way to use the specific "keybd_event" for a window? Could you demonstrate an example of using with _SendMessage with notepad? I researched it but didn't understand it very well Link to comment Share on other sites More sharing options...
Jonatas Posted October 30, 2019 Share Posted October 30, 2019 About _SendMessage, I found this perfect example of Oasis375 #include <SendMessage.au3> #include <WindowsConstants.au3> Run("notepad.exe") $hWnd = WinWait("[CLASS:Notepad]", "", 10) $hControl = ControlGetHandle($hWnd, "", "Edit1") $text = "this is a line" $struct_string = DllStructCreate("char[" & StringLen($text) + 1 & "]") DllStructSetData($struct_string, 1, $text) _SendMessageA($hControl, $WM_SETTEXT, 0, DllStructGetPtr($struct_string)) Norm73 1 Link to comment Share on other sites More sharing options...
Norm73 Posted June 19, 2022 Share Posted June 19, 2022 (edited) please tell me how to send a virtual key combination, for example, Alt+a, "^a", "{LCTRL}a" When I send $VK_SELECT (SELECT key) nothing happens _Send_Virtual_Key(0x29) ; -> VK_SELECT - SELECT key Func _Send_Virtual_Key($iCode) If Not IsInt($iCode) Then Return DllCall('user32.dll', 'int', 'keybd_event', 'int', $iCode, 'int', 0, 'int', 0, 'ptr', 0) DllCall('user32.dll', 'int', 'keybd_event', 'int', $iCode, 'int', 0, 'int', 2, 'ptr', 0) EndFunc Edited June 19, 2022 by Norm73 Link to comment Share on other sites More sharing options...
jugador Posted June 19, 2022 Share Posted June 19, 2022 virtual key combination (Left CONTROL key + A) DllCall('user32.dll', 'int', 'keybd_event', 'int', 0xA2, 'int', 0, 'int', 0, 'ptr', 0) ;~ Left CONTROL key DllCall('user32.dll', 'int', 'keybd_event', 'int', 0x41, 'int', 0, 'int', 0, 'ptr', 0) ;~ A DllCall('user32.dll', 'int', 'keybd_event', 'int', 0x41, 'int', 0, 'int', 2, 'ptr', 0) DllCall('user32.dll', 'int', 'keybd_event', 'int', 0xA2, 'int', 0, 'int', 2, 'ptr', 0) Norm73 1 Link to comment Share on other sites More sharing options...
Norm73 Posted June 19, 2022 Share Posted June 19, 2022 (edited) 53 minutes ago, jugador said: virtual key combination (Left CONTROL key + A) Thanks for the quick reply It works very well! I want to make this message more reliable, but I don't know how to send a combination to a control in a window. Like this: #include <SendMessage.au3> #include <WindowsConstants.au3> Run("notepad.exe") $hWnd = WinWait("[CLASS:Notepad]", "", 10) $hControl = ControlGetHandle($hWnd, "", "Edit1") $text = "this is a line" $struct_string = DllStructCreate("char[" & StringLen($text) + 1 & "]") DllStructSetData($struct_string, 1, $text) _SendMessageA($hControl, $WM_SETTEXT, 0, DllStructGetPtr($struct_string)) Edited June 19, 2022 by Norm73 Link to comment Share on other sites More sharing options...
jugador Posted June 19, 2022 Share Posted June 19, 2022 (edited) first sets input focus to a given control on a window using ControlFocus then try your virtual key combination Edited June 19, 2022 by jugador Norm73 1 Link to comment Share on other sites More sharing options...
Norm73 Posted June 19, 2022 Share Posted June 19, 2022 If it's not feasible, I probably don't have a choice. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now