Solved

Keyboard + SendInput + erratic results + opens Menus

Posted on 2009-05-04
6
665 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now