Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Keyboard + SendInput + erratic results + opens Menus

Posted on 2009-05-04
6
Medium Priority
?
674 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 1000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

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.  …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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 question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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