DeltaRocked Posted January 28, 2011 Posted January 28, 2011 (edited) Hi All, I am unable to find the caretpos within a browser or MSWord as I want to insert a character at the caret's current position without using Send or Controlsend. The reason for not using Send or ControlSend is that these functions generate WM_CHAR / WM_KEYUP / WM_KEYDOWN messages which are detrimental towards the development of a Virtual-keyboard. I am at my wits end . Thanks in Advance. DeltaRocked. Edited February 3, 2011 by deltarocked
PsaltyDS Posted January 28, 2011 Posted January 28, 2011 I don't have any idea what you mean by "detrimental towards the development of a Virtual-keyboard", but you could look at the UDF files IE.au3 and Word.au3 to see how the COM interfaces are used. So, how are routine windows messages "detrimental towards the development of a Virtual-keyboard"? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
DeltaRocked Posted January 29, 2011 Author Posted January 29, 2011 (edited) I don't have any idea what you mean by "detrimental towards the development of a Virtual-keyboard", but you could look at the UDF files IE.au3 and Word.au3 to see how the COM interfaces are used. So, how are routine windows messages "detrimental towards the development of a Virtual-keyboard"?Hi PSaltyDS,for past few hours even I was working on the same as quoted by you, Thanks. First the Logic for Virtual keyboard:1: If its a GUI get the editable Control which has the focus and use controlcommand with editpaste as the command. 2: If its a browser then a: enumarate the DOM objects which have contentedit enabled b: get the text within those objects for reference c: then use Send('~') (the reason for sending ~ is that it is accessible after shift key is pressed) d: Send function will send the ~ to the current cursor position , which in this case is a dom object. e: get the text from enumerated objects and detect the string which has changed - this is the object which has the current keyboard focus.f: replace ~ with the character you have chosen to enter** when using special keys eg. backspace do not use this method, just use plain simple Send The reason for using this logic is that it is not possible to find the DOM Object which has the focus (according to various forums - if its possible then its great need to find the existence of this) Now for the later part : Windows Messagesif Send or ControlSend is used then keystrokes are sent as Windows Messages i.e. WM_Char or WM_KeyDown or WM_Keyup, these messages are esaily accesible using on the of the examples which comes along with Autoit Help. So for a virtual Keyboard which uses these functions is not at all acceptable.I have come across a Virtual Keyboard which uses WM_PASTE, or in plain simple language issues CTRL+V cool trick but .... useless if you are also monitoring the clipboard.When, we are using DOM, in terms of security even this method is a bit diecy as there are form-grabbers available , I havent yet thought on how to overcome these but as it is said , wrt time even this knowledge shall be made available. I wanted to post the code but my last thread was locked cause some idiot was interested in developing keyloggers , so this time around - no code till its finished, only suggestions and logic.With Autoit around, I have realized that it offers such a great deal that a few words of suggestions is more than enough to complete your task (though it takes time), I got the whole time in this world as tomorrow is Sunday and 24 hours are more than enough once we have the logic .RegardsDeltaRocked. Edited January 29, 2011 by deltarocked
DeltaRocked Posted January 31, 2011 Author Posted January 31, 2011 (edited) Hi, Phase 1 Complete. Phase II issues : Unable to get the DOM element which has the keyboard focus nor am I able to get the Caret Position. Through any normally available UDFs Used the workaround to find the DOM Element which has the keyboard focus: 1: On winActive and the window have focus with COntrolID = 'Internet Explorer_Server' grab all the form fields and their individual texts store them in an array . 2: ControlSend('Wintitle','', 'Internet Explorer_Server1','?')) 3: grab all the form fields and their individual texts store them in a second array . 4: Compare the values which have changed and then we have the DOM Element which has the keyboard focus. Problem faced : If I use _IEFormElementSetValue then the cursor changes its position to the end. Question: Is there any other method by way of which I can get the cursor (read - caret) position from within the dom-element? or Insert a character at the caret position within the DOM Element Another workaround available by way of inserting javascript but code injection is something which I want to avoid. PixelChecksum is another workaround after procuring the X Y Cordinates by using IEPropertyget, but that will give me the screen cordinates. thanks in advance. regards Deltarocked. Edited January 31, 2011 by deltarocked
PsaltyDS Posted February 1, 2011 Posted February 1, 2011 The IE document object with focus should be returned by: $oActive = $oIE.activeElement I don't know if you can get the cursor position inside an input element. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
DeltaRocked Posted February 1, 2011 Author Posted February 1, 2011 (edited) The IE document object with focus should be returned by: $oActive = $oIE.activeElement I don't know if you can get the cursor position inside an input element. [Edited] yup ... only the active element ...but i think it provides the tagname (by BigDaddy), tried searching for ID based ... $sActiveElement = $oIE_form.document.activeElement.tagName DOM/COM was never my forte ... For past few days I have been obsessed with this problem. Trying to understand the internals of relationship between the caret in various applications and windows. Presently am working on the code based on the logic from the previous entry, I think I will paste that code , cause one brain is just not enough. regards DeltaRocked. Edited February 1, 2011 by deltarocked
DeltaRocked Posted February 2, 2011 Author Posted February 2, 2011 (edited) hi,came across a problem with multiple tabs in IE.When the keyboard focus is in the second tab still it returns the value from the first tab.Edit:Found the solution in this threadhave to use $oIE = _IEAttach($ie_handle, 'Embedded')Now lets check out the limitations... Edit : Changed the code.expandcollapse popup#include <ie.au3> #include <array.au3> Opt("WinTextMatchMode", 1) Sleep(1500) $ie_handle = WinWaitActive(WinGetTitle('', '')) $control_class_namenn = ControlGetFocus($ie_handle) If $ie_handle <> 0 And StringInStr($control_class_namenn, 'Internet Explorer_Server', 0) > 0 Then get_keyboard_focus($ie_handle, $control_class_namenn) Else Send('a') ControlCommand($ie_handle, '', $control_class_namenn, 'EditPaste', 'a') EndIf Func get_keyboard_focus($ie_handle, $control_class_namenn) $oIE = _IEAttach($ie_handle, 'Embedded') $oActive_e = $oIE.document.activeElement.name $oForms = _IEFormGetCollection($oIE) $iNumForms = @extended Local $string = '' For $i = 0 To $iNumForms - 1 $oForm = _IEFormGetCollection($oIE, $i) $val = _IEFormElementGetObjByName($oForm, $oActive_e) If @error == 0 Then $element_val_old = _IEFormElementGetValue($val) $i_old = $i ExitLoop EndIf Next ;~ MsgBox(4096,'string',$element_val) ;get form_field_names and Form_Field_data ;Store form_field_names and Form_Field_data ;~ Send("?") ControlSend($ie_handle, '', $control_class_namenn, "?") ;~ $oActive_e = $oIE.document.activeElement.name $oForm = _IEFormGetCollection($oIE, $i_old) $val = _IEFormElementGetObjByName($oForm, $oActive_e) $element_val_new = _IEFormElementGetValue($val) ControlSend($ie_handle, '', $control_class_namenn, "{BACKSPACE}") MsgBox(0, '', $element_val_old & ' -- ' & $element_val_new) ;get Form_Field_data ;Compare with previous Form_Field_data EndFunc ;==>get_keyboard_focus Edited February 3, 2011 by deltarocked
DeltaRocked Posted February 3, 2011 Author Posted February 3, 2011 (edited) Hi PsaltyDS, Inserting a character at the Caret Position within IE has been solved Solved.Thanks for your help and your timely inputs. Thanks to Manadar and BigDaddy too and who will forget Dale. Here is the complete code. Now will rework on the Virtual keyboard to include this code. need to add error handling (am bad at this too) #include <ie.au3> #include <array.au3> Opt("WinTextMatchMode", 1) Sleep(1500) $ie_handle = WinWaitActive(WinGetTitle('', '')) $control_class_namenn = ControlGetFocus($ie_handle) If $ie_handle <> 0 And StringInStr($control_class_namenn, 'Internet Explorer_Server', 0) > 0 Then get_keyboard_focus($ie_handle, $control_class_namenn) Else Send('a') ControlCommand($ie_handle, '', $control_class_namenn, 'EditPaste', 'a') EndIf Func get_keyboard_focus($ie_handle, $control_class_namenn) $oIE = _IEAttach($ie_handle, 'Embedded') $oActive_e = $oIE.document.activeElement.name $oForms = _IEFormGetCollection($oIE) $iNumForms = @extended Local $string = '' For $i = 0 To $iNumForms - 1 $oForm = _IEFormGetCollection($oIE, $i) $val = _IEFormElementGetObjByName($oForm, $oActive_e) If @error == 0 Then $element_val_old = $val.value $i_old = $i ExitLoop EndIf Next $oForm = _IEFormGetCollection($oIE, $i_old) $val = _IEFormElementGetObjByName($oForm, $oActive_e) $element_val_new = $val.value $oRange = $val.document.selection.createRange() $orange.text='e' $element_val_new = $val.value MsgBox(0, '', $element_val_old & @CRLF & $element_val_new) EndFunc ;==>get_keyboard_focus Edited February 3, 2011 by deltarocked
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