Solved

Keyboard + SendInput + erratic results + opens Menus

Posted on 2009-05-04
6
668 Views
Last Modified: 2013-11-27
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

0
Comment
Question by:simpath
  • 2
  • 2
  • 2
6 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24301120
simpath,

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
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24314932
Are you using ^A or CTRL+A? CTRL = ^, Shift = + etc.

http://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm
0
 

Author Comment

by:simpath
ID: 24325805
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.SetForegroundWindow(Me.Hwnd_TextControl)


'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.RepaintWindow_Hwnd(Hwnd_TextControl)
DoEvents

'RETURN Value
GetWordBeforeCaret_SENDKEY = Shortcut

'Activate
Call Program_API_Module1.SetForegroundWindow(Hwnd_TextControl)

End Function

'********************


0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 24326043
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24331815
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
0
 

Accepted Solution

by:
simpath earned 0 total points
ID: 24335076
Dear CodeCruiser

I changed the 0 to True, and read the links, but it still wasn't the answer.

I think that the problem is a constant repertoir of interference from additional keystrokes. and the timer event, and so I am now working with keyboard hooks,

Dan Applemans Spyware program provides this functionality.

***********

Dear boag2000

Yes I do know about Microsoft Word Autoreplace, and this is a brilliant thing, however I am trying to write my own Word expansion software app, in VB6, and already I have about 50 thousand records.

Many thanks for both contributions.

I will allocate 250 points to CodeCruiser

Simpath
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
T-SQL Debugging - Temp Object Content 2 54
Is COM supported from Apache 1 53
WPF issue with Trigger 2 105
What .NET URL re-routing tool did I use? 2 54
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question