simpath
asked on
Keyboard + SendInput + erratic results + opens Menus
I am trying to build a word expansion application in visual basic 6.
(eg "atis" will be replaced with "and there is" )
I am trying to use Sendkeys / SendInput to input keystrokes to an application (eg. Word, Wordpad etc), namely CTL, SHIFT, LEFT ARROW, RIGHT ARROW
in order to select the word the Caret is in (ie. atis), and then do a word replace ie, "atis" becomes "and there is".
The problem is that the Sendinput code (CTL, SHIFT, LEFT, RIGHT etc) causes erratic jumps of the caret, and will often open a menu.
I guess that I need to block user input (efg BlockInput API) during the routine,
but this doesnt seem to work properly
Any Ideas Anybody
(eg "atis" will be replaced with "and there is" )
I am trying to use Sendkeys / SendInput to input keystrokes to an application (eg. Word, Wordpad etc), namely CTL, SHIFT, LEFT ARROW, RIGHT ARROW
in order to select the word the Caret is in (ie. atis), and then do a word replace ie, "atis" becomes "and there is".
The problem is that the Sendinput code (CTL, SHIFT, LEFT, RIGHT etc) causes erratic jumps of the caret, and will often open a menu.
I guess that I need to block user input (efg BlockInput API) during the routine,
but this doesnt seem to work properly
Any Ideas Anybody
Are you using ^A or CTRL+A? CTRL = ^, Shift = + etc.
http://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm
http://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm
ASKER
Hi guys
Many thanks for the response.
I am trying to select the left hand portion of a word with the keystroke combination
CTL + SHIFT + LEFT.
Here is some of the code:
'*******
Public Function GetWordBeforeCaret_SENDKEY () As String
'NB. ^ Ctrl ! Alt + Shift
'****NB. USE the Cliboard to transfer text
'*** NB. SendKey = Use KeySend BAS module
'*** NB. USE THE LOCKWINDOWUPDATE / SETREDRAW FUNCTION to make selection code transparent to USER,
Dim rval As Long
Dim Shortcut As String
Dim SCLen As Integer
Dim i As Integer
On Error Resume Next
'hwnd = Me.Hwnd_TextControl
'Activate
Call Program_API_Module1.SetFor egroundWin dow(Me.Hwn d_TextCont rol)
'Block RePaint
'Call SetRedraw(Hwnd_TextControl , False)
LockWindowUpdate (Hwnd_TextControl) 'WORKS PERFECTLY
DoEvents
'Select TO START OF WORD (= CTL + SHIFT + LEFT)
Call Sendkey("^+{LEFT}", 0) 'LOC (= select word, left of Curser).
DoEvents
'Copy to Clipboard
SendMessage Hwnd_TextControl, WM_COPY, 0, 0
DoEvents
'Get Shortcut + SCLen
Shortcut = Clipboard.GetText
SCLen = Len(Shortcut)
Clipboard.Clear
'*******
'Re-set to Caret
Call Sendkey("^+{RIGHT}", 0) 'ROC (= select word, right of Curser).
Call Sendkey("^{LEFT}", 0) 'SOW (= select start of word).
DoEvents
i = 0
Do Until i = SCLen 'Move back to Curser Pos
Call Sendkey("{RIGHT}", 0) 'Move right, one character at a time.
i = i + 1
Loop
DoEvents
'Allow Repaint
'Call SetRedraw(Hwnd_TextControl , True)
LockWindowUpdate False 'WORKS PERFECTLY
DoEvents
'REPAINT
Call Program_API_RePaintWindow. RepaintWin dow_Hwnd(H wnd_TextCo ntrol)
DoEvents
'RETURN Value
GetWordBeforeCaret_SENDKEY = Shortcut
'Activate
Call Program_API_Module1.SetFor egroundWin dow(Hwnd_T extControl )
End Function
'********************
Many thanks for the response.
I am trying to select the left hand portion of a word with the keystroke combination
CTL + SHIFT + LEFT.
Here is some of the code:
'*******
Public Function GetWordBeforeCaret_SENDKEY
'NB. ^ Ctrl ! Alt + Shift
'****NB. USE the Cliboard to transfer text
'*** NB. SendKey = Use KeySend BAS module
'*** NB. USE THE LOCKWINDOWUPDATE / SETREDRAW FUNCTION to make selection code transparent to USER,
Dim rval As Long
Dim Shortcut As String
Dim SCLen As Integer
Dim i As Integer
On Error Resume Next
'hwnd = Me.Hwnd_TextControl
'Activate
Call Program_API_Module1.SetFor
'Block RePaint
'Call SetRedraw(Hwnd_TextControl
LockWindowUpdate (Hwnd_TextControl) 'WORKS PERFECTLY
DoEvents
'Select TO START OF WORD (= CTL + SHIFT + LEFT)
Call Sendkey("^+{LEFT}", 0) 'LOC (= select word, left of Curser).
DoEvents
'Copy to Clipboard
SendMessage Hwnd_TextControl, WM_COPY, 0, 0
DoEvents
'Get Shortcut + SCLen
Shortcut = Clipboard.GetText
SCLen = Len(Shortcut)
Clipboard.Clear
'*******
'Re-set to Caret
Call Sendkey("^+{RIGHT}", 0) 'ROC (= select word, right of Curser).
Call Sendkey("^{LEFT}", 0) 'SOW (= select start of word).
DoEvents
i = 0
Do Until i = SCLen 'Move back to Curser Pos
Call Sendkey("{RIGHT}", 0) 'Move right, one character at a time.
i = i + 1
Loop
DoEvents
'Allow Repaint
'Call SetRedraw(Hwnd_TextControl
LockWindowUpdate False 'WORKS PERFECTLY
DoEvents
'REPAINT
Call Program_API_RePaintWindow.
DoEvents
'RETURN Value
GetWordBeforeCaret_SENDKEY
'Activate
Call Program_API_Module1.SetFor
End Function
'********************
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
simpath,
<I am trying to select the left hand portion of a word with the keystroke combination>
...Then I am confused, this is not what you asked for in your original post.
<do a word replace ie, "atis" becomes "and there is".>
This is what my post demonstrates.
Did you look at it?
Did you try it?
JeffCoachman
<I am trying to select the left hand portion of a word with the keystroke combination>
...Then I am confused, this is not what you asked for in your original post.
<do a word replace ie, "atis" becomes "and there is".>
This is what my post demonstrates.
Did you look at it?
Did you try it?
JeffCoachman
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This functionality is built into Word already.
It's called "AutoCorrect"
Type the characters you want.
Right-Click the characters-->Auto Correct--AutoCorrect Options.
Why re-invent the wheel?
;-)
JeffCoachman
untitled.JPG