Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ to Delphi

Status
Not open for further replies.

Hubba

Programmer
May 17, 2003
6
US
I have been tryin to convert a piece of C++ code to delphi for some time now, Can anyone help?

//----------------------------------------------------------
// MsgSetHandler()
//
// Sets the handler for a particular message. In the context of MMB, a "handler"
// is a keystroke that we send to the app. This is really the only way to send
// a message to MMB script. The script author sets up a script to handle the
// message, chooses a keystroke to trigger it, then tells us what that keystroke
// is. That keystroke comes to us in the form of a string.
//
// Here's some examples:
//
// "CONTROL+ALT+X"
// "a"
// "SHIFT+6"
//
//------------------------------------------------------------------------------
void MsgSetHandler (MmbMsg msg, const char* handler)
{
DEBUG_PRINT ("MsgSetHandler(%s)\n", handler);

m_hotkeys[msg].ParseFromString (handler);
}

//------------------------------------------------------------------------------
// MsgSend() -
//
// Sends the keystroke associated with the specified message to the MMB window.
//------------------------------------------------------------------------------
void MsgSend (MmbMsg msg)
{
DEBUG_PRINT ("MsgSend()\n");

assert (0 <= msg && msg < NumMessages);
assert (msg < m_hotkeys.size());

KeyboardMsg& keystroke = m_hotkeys[msg];

if (keystroke.keycode == 0)
{
SyntaxError (&quot;No handler set for this message!&quot;);
}

keystroke.Send();
}

Any help many thanks
 
I may be off the mark here because I dont understand what you mean by 'MMB'. However..

The beauty of Delphi is that we dont always have to work at such a low level.

All Delphi Forms (and many other components) have an OnkeyDown event. Use this to capture keystrokes.
The variable 'Key' can be tested against a set of Constants.
there are also other constants which indicate the Shift Alt
and Control Keys. these are passed in the 'shift' parameter.

e.g. to detect Shift/Up or Shift/down.
if (Key in [VK_UP, VK_DOWN]) and (Shift = ssShift) then
doaction;

The Virtual Key constants can all be found in 'Windows.pas'
Also look in the help at the API Function
GetKeyState(Virtualkey);
This will return True if the specifed Key is Pressed.
and may provide a means for you to Pick up on other Multiple key presses.

Hope this helps
Steve
 
Nor exactly what Im looking for sggaunt,

I need to pass a SendMessage set of keys to another app like (Ctrl+A) or something
 
Hubba
Ah A different ball game altogether, I think part of the problem here is that your C++ examples require a fair degree of expertise in that language, and there isn't enough commenting for me to workout what is going on.
I am sure this can be done in Delphi using Window Handles, message directives and the like.
I know there are peoople in the forum who have experience with this sort of thing so over to you guys..
Sorry I coudnt be of more help
Steve.
 
sggaunt

Thanks for taking the time, If I get it I will post the answer here.
 
This is what I needed...

var
h: hwnd;
begin
h := FIndWindow(nil, PCHar('Forma'));
if h <> 0 then begin
SetForegroundWIndow(h);
keybd_event(VK_CONTROL,0,0,0);
keybd_event(VK_MENU,0,0,0);
keybd_event(ORD('A'),0,0,0);
keybd_event(ORD('A'),0,KEYEVENTF_KEYUP,0);
keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);
keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
end;
end;


Thanks to all
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top