Zohar Posted December 19, 2009 Share Posted December 19, 2009 (edited) Hello I need a function that when called, will wait for a Single Key from the user. The Key can be a letter or number. What I thought to do is this: 1) Show a small Window, with no controls on it 2) Wait for a KeyPress 3) When getting a KeyPress, Close the Window, and Return the Pressed Key But after I do GUICreate(), there's no event for KeyPress. What would be th simplest way to do it? Thank you Edited January 9, 2010 by Zohar Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 19, 2009 Moderators Share Posted December 19, 2009 Zohar,What you are asking for is essentially a KeyLogger, which is one of the taboo subjects here - look here to see why.However, as Jon does say that "Posts on how to check for a few keys being pressed" are reasonably acceptable, I would point you in the direction of GUICtrlRead and a blank Input control. M23 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...
Developers Jos Posted December 19, 2009 Developers Share Posted December 19, 2009 (edited) Just use a the HotKeySet() or _IsPressed() to wait for this one key. When you want to wait for any key you need to monitor all keystrokes and its a kinda keylogger... and we do not want that here...do we? Jos Edited December 19, 2009 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zohar Posted December 19, 2009 Author Share Posted December 19, 2009 (edited) HiIf I wanted to create a KeyLogger, I think I would use _IsPressed() Or simply download one from the internet What I need here is different.I need to wait for a Single key from the user.Also I need a small Window to show up.And also I need to Wait for it, because it's a selection by the user. for that Reason IsPressed() is not good for me.BTW I created it in .NET with a single line of code.private void Form1_KeyPress(object sender, KeyPressEventArgs e) { this.Text=e.KeyChar.ToString(); }But since AutoIt is not .NET, then I need to make it in AutoIt so it can communicate with the rest of my AutoIt Code.Regarding the ideas you wrote:Melba:From what I see in the Help, GUICtrlRead has nothing to do with Keys being pressed.. It reads the content of a Control, not a KeyPress.Jos:Using HotKeySet() will not be good here, because it is not a HotKey.The user has to make a Selection, by pressing 1 Key(Number or Letter).I will not add a HotKeySet() for every letter and number.If anyone has other ideas, please write. Edited December 19, 2009 by Zohar Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 19, 2009 Moderators Share Posted December 19, 2009 (edited) Zohar,Melba:From what I see in the Help, GUICtrlRead has nothing to do with Keys being pressedCorrect, but read my post again - GUICtrlRead is only part of what I suggested. "click"M23P.S. And if you do "get" it, do NOT post it here! Edited December 19, 2009 by Melba23 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...
wolf9228 Posted December 19, 2009 Share Posted December 19, 2009 HelloI need a function that when called, will wait for a Single Key from the user.The Key can be a letter or number.What I thought to do is this:1) Show a small Window, with no controls on it2) Wait for a KeyPress3) When getting a KeyPress, Close the Window, and Return the Pressed KeyBut after I do GUICreate(), there's no event for KeyPress.What would be th simplest way to do it?Thank you_WinAPI_SetWindowsHookEx http://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_SetWindowsHookEx.htm صرح السماء كان هنا Link to comment Share on other sites More sharing options...
Zohar Posted December 19, 2009 Author Share Posted December 19, 2009 (edited) Correct, but read my post again - GUICtrlRead is only part of what I suggested. OHHSorry, I now understand what you mean.It will work.. but it will not behave as I want..I do not want it to get into a textbox.. I simply want to get an event when a key is pressed in the window - a window with no controls..and to return it as the function's result.. :/Thanks tho_WinAPI_SetWindowsHookEx http://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_SetWindowsHookEx.htmHi Wolf Thank you for the idea,but do I really need to Set a Hook to get a Key Input from within a window that I created?If it was a third party application's window, I would understand..but from mine too?Maybe I should stick with my .NET implementation, and have it communicate with AutoIt?:/ Edited December 19, 2009 by Zohar Link to comment Share on other sites More sharing options...
wolf9228 Posted December 19, 2009 Share Posted December 19, 2009 $WH_KEYBOARD $WH_KEYBOARD - Installs a hook procedure that monitors keystroke messages $dwThreadId _WinAPI_GetCurrentThreadId() Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Global $Key GUICreate(" ", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES $Input = GUICtrlCreateInput("", 10, 5, 300, 20) GUISetState() Local $hmod $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") $hmod = _WinAPI_GetModuleHandle(0) $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD, DllCallbackGetPtr($hStub_KeyProc) _ , 0,_WinAPI_GetCurrentThreadId()) $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() WEnd Func IS_PRESSED($lParam) Return int(BitAND($lParam,int(0x40000000))) EndFunc Func IS_RELEASED($lParam) Return Not int(BitAND($lParam,int(0x40000000))) EndFunc Func _KeyProc($nCode, $wParam, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndIf if IS_PRESSED($lParam) Then _ GUICtrlSetData($Input, "Pressed " & Chr($wParam)) Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc Func Cleanup() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) EndFunc ;==>Cleanup صرح السماء كان هنا Link to comment Share on other sites More sharing options...
Zohar Posted December 19, 2009 Author Share Posted December 19, 2009 (edited) Dear wolf9228 I sincerely thank you for that. Yet I must admit that I think I will stay with my .NET window. It's amazing how a simple functionality, can turn into such a difficult process(relatively). All I wanted is to give the user the ability to choose from many options, via pressing 1 key. And it became a code that contains hooks, my god (: oh.. If only AutoIt was in .NET. Such wonderful things could've been created, without wasting excess energy.. And to remind you all, an implementation in .NET: private void Form1_KeyPress(object sender, KeyPressEventArgs e) { this.Text=e.KeyChar.ToString(); } Edited December 19, 2009 by Zohar Link to comment Share on other sites More sharing options...
Valik Posted December 20, 2009 Share Posted December 20, 2009 oh..If only AutoIt was in .NET.Such wonderful things could've been created, without wasting excess energy..If AutoIt was in .NET it would be a slow-as-fuck bloated piece of shit nobody gave a damn about. Link to comment Share on other sites More sharing options...
darkjohn20 Posted December 20, 2009 Share Posted December 20, 2009 If AutoIt was in .NET it would be a slow-as-fuck bloated piece of shit nobody gave a damn about.Amen. Link to comment Share on other sites More sharing options...
Zohar Posted December 21, 2009 Author Share Posted December 21, 2009 If AutoIt was in .NET it would be a slow-as-fuck bloated piece of shit nobody gave a damn about..NET is not slow.And let me remind you AutoIt uses an Interpreter too.. Link to comment Share on other sites More sharing options...
Valik Posted December 21, 2009 Share Posted December 21, 2009 .NET is not slow.It's slower than native code. Startup times for .NET applications is absurd. Giving up runtime performance to make compile-time code writing easier is just asinine at best and utterly stupid when any half-baked fucktard can sit down and write something runnable but certainly not passable or functional.And let me remind you AutoIt uses an Interpreter too..Really? I didn't know that. Also, do you know what would happen if AutoIt were written in .NET? You'd have the same slow speed AutoIt has now on top of the performance penalties .NET imposes. Add in the fact that it would require several MB of runtimes (The .NET framework, obviously) and well... it would be a slow-as-fuck bloated piece of shit. That nobody would care about. 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