Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SendInput - Calculator and putting numbers

224 views
Skip to first unread message

Arne Ortlinghaus

unread,
May 30, 2013, 5:39:08 AM5/30/13
to
Has someone already used the WinAPI function Sendinput?

I have to call the windows calculator from my program and send a number.
With wm_settext and wm_paste it is not possible to put a number. Now I want
to simulate key strokes.

Arne Ortlinghaus
ACS Data Systems

dlzc

unread,
May 30, 2013, 10:10:56 AM5/30/13
to
Dear Arne Ortlinghaus:

On Thursday, May 30, 2013 2:39:08 AM UTC-7, Arne Ortlinghaus wrote:
...
> I have to call the windows calculator from my
> program and send a number. With wm_settext and
> wm_paste it is not possible to put a number. Now
> I want to simulate key strokes.

Probably enough searchable stuff in this link to get you going. His example code is C++ for pushing keystrokes to Windows Calculator... so you'd look for similar API function names.

You will probably have to convert your number to text, and send that.

David A. Smith

Jamal

unread,
May 31, 2013, 12:57:46 PM5/31/13
to
The following terminal app sample works with PostMessage( ) and WM_KEYUP.
This may be alternate way.

FUNCTION Start()

LOCAL h AS PTR

// run MS Calculator first

h := FindWindow(NULL_PTR, String2Psz("Calculator"))


PostMessage(h, WM_KEYUP, 0x69, 0L ) // NUMPAD 9

PostMessage(h, WM_KEYUP, 0x6D, 0L ) // NUMPAD -

PostMessage(h, WM_KEYUP, 0x65, 0L ) // NUMPAD 5

WAIT

PostMessage(h, WM_KEYUP, 0x13, 0L ) // NUMPAD ENTER

WAIT

RETURN NIL

Jamal

"Arne Ortlinghaus" wrote in message news:ko76fn$d87$1...@dont-email.me...

Arne Ortlinghaus

unread,
Jun 3, 2013, 6:10:21 AM6/3/13
to
Hi Jamal,

thank you. Indeed you solution has helped me saving some time.

It works good except for the enter key. On my Win 7 machine it is ignored,
also other characters like Return 0xD or 0xA. I would need it for
implementing sending negative numbers to the calculator.

Arne

"Jamal" <ja...@examples.net> schrieb im Newsbeitrag
news:koakq5$dbd$1...@speranza.aioe.org...

Gerhard Bunzel

unread,
Jun 3, 2013, 7:21:56 AM6/3/13
to
Arne,

here you will find a vb.net-sample to get the Windows Calc value with
Win32-Standard-API.
With SetWindowText() it should be possible, to send your number.

http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/e9b2c76c-c96e-46a8-b5cc-d26798e831ae/

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633546(v=vs.85).aspx


hth

Gerhard


"Arne Ortlinghaus" <Arne.Ort...@acs.it> schrieb im Newsbeitrag
news:ko76fn$d87$1...@dont-email.me...

Gerhard Bunzel

unread,
Jun 3, 2013, 8:01:34 AM6/3/13
to
Hi Arne,

have done a smal test with a german windows:

Set text in in calculator:
LOCAL hWnd AS PTR
LOCAL cText AS STRING

hWnd := FindWindow(String2Psz("SciCalc"), String2Psz("Rechner"))
hWnd := FindWindowEx(hwnd, 0, String2Psz("Edit"), NULL_PSZ)

cText := "1234,789"

iRet := SendMessage(hwnd, WM_SETTEXT, 0, LONG(_CAST, String2Psz(cText)))


Get text from calculator:
LOCAL hWnd AS PTR
LOCAL cText AS STRING
LOCAL iLen AS LONG
LOCAL iRet AS LONG
LOCAL pBuff AS PTR

hWnd := FindWindow(String2Psz("SciCalc"), String2Psz("Rechner"))
hWnd := FindWindowEx(hwnd, 0, String2Psz("Edit"), NULL_PSZ)

// First, get the text lenght.
iLen := SendMessage( hWnd, WM_GETTEXTLENGTH, 0, 0L )

IF iLen > 0
pBuff := MemAlloc( iLen + 1 )
IF pBuff <> NULL_PTR
iRet := SendMessage(hWnd, WM_GETTEXT, DWORD(_CAST, iLen), LONG(_CAST,
pBuff))
IF iRet > 0
cText := Psz2String( pBuff )
ENDIF
MemFree( pBuff )
ENDIF
ENDIF


HTH

Gerhard



"Gerhard Bunzel" <g.bu...@domonet.de> schrieb im Newsbeitrag
news:kohu8i$bqv$1...@news.m-online.net...

Arne Ortlinghaus

unread,
Jun 4, 2013, 12:07:27 PM6/4/13
to
Hi Gerhard,

very nice.
I tried wm_settext with the main window of the calculator and got only a
different caption.
The
hWnd := FindWindowEx(hwnd, 0, String2Psz("Edit"), NULL_PSZ)
is a nice trick.

Thank you
Arne


"Gerhard Bunzel" <g.bu...@domonet.de> schrieb im Newsbeitrag
news:koi0is$4e2$1...@news.m-online.net...
0 new messages