Solved

Keyboard + SendInput + erratic results + opens Menus

Posted on 2009-05-04
6
671 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Standards for file storage. 3 36
How Does Quick Books store date / time? 3 109
SignTool Error with Windows 10 5 220
What .NET URL re-routing tool did I use? 2 85
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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