TmTFx
November 9, 2021, 2:39pm
1
Hi,
I was playing with Bethon (python implementation of C++ BeOS API), and I needed to postmessage a keypress to a TextView.
basicly the idea was to recreate the BMessage (I know that there are system bmessages and an “in-app” bmessages which you can detect with the IsSystem() function), structured like this:
endkpress=BMessage(END_DOWN_MSG)
now=uptime._uptime_beos()
now=now*1000000
endkpress.AddInt64('when',long(now))
endkpress.AddInt32('key',60)
endkpress.AddInt32('modifiers',32)
endkpress.AddInt8('states',0)
endkpress.AddInt8('byte',97)
endkpress.AddString('bytes',"a")
endkpress.AddInt32('raw_char',97)
BApplication.be_app.PostMessage(endkpress) #eventually WindowAt(0).
endkpress=BMessage(END_UP_MSG)
now=uptime._uptime_beos()
now=now*1000000
endkpress.AddInt64('when',long(now))
endkpress.AddInt32('key',60)
endkpress.AddInt32('modifiers',32)
endkpress.AddInt8('states',0)
endkpress.AddInt8('byte',97)
endkpress.AddString('bytes',"a")
endkpress.AddInt32('raw_char',97)
BApplication.be_app.PostMessage(endkpress) #eventually WindowAt(0).
as it seems it’s not working if you know, is there an alternative solution?
memsom
November 9, 2021, 3:16pm
2
You can do something like this
void StrokeItView::dokeyevent( key_event_t event )
{
// this is an extremely truncated version os a routine lifted from VNC Server/SKBD
BMessage msg;
int32 curr_modifiers=0; // modifiers
if ( event.down )
msg.what = B_KEY_DOWN;
else
msg.what = B_KEY_UP;
char string[4] = {0,0,0,0};
switch (event.key)
{
case 13:
msg.AddInt32("key", 0x47);
string[0] = B_RETURN;
break;
/*case ???: /////// DELETE as in char to left, not BACKSPACE
msg.AddInt32("key", 0x34);
string[0] = B_DELETE;
break;*/
case 8:
msg.AddInt32("key", 0x1e);
string[0] = B_BACKSPACE;
break;
default:
//msg.AddInt32("key", event.key); // this has an odd effect in terminal
string[0] = event.key;
}
msg.AddString("bytes", string);
for ( int i=0; string[i]; i++ )
msg.AddInt8("byte", string[i]);
msg.AddInt32("modifiers", curr_modifiers);
#ifdef KEYBOARD_DEBUG
msg.PrintToStream();
#endif
if ( msg.FlattenedSize() > 20 )
{ // flatten and send if
input_port = find_port("StrokeIT Input port");
if ( input_port < 0 )
cout << "Error connecting to input server add-on" << endl;
//else
// cout << "Input server add-on port id: " << input_port << "\n";
char * buffer = new char[msg.FlattenedSize()];
msg.Flatten( buffer, msg.FlattenedSize() );
if ( write_port( input_port, 123, buffer, msg.FlattenedSize() ) != B_OK )
{
cout << "Error writing to input add-on port\n";
}
delete [] buffer;
}
}
TmTFx
November 9, 2021, 3:37pm
3
Mh… I’m trying to understand the C++ code ^_^’… Am I wrong if I say that the code reads the input and modifies the output?
memsom
November 9, 2021, 4:11pm
4
Sorry - I was on my phone and missed off this part:
/*
This code is based upon the input server add on from the:
BeOS VNC Server component by Mikael Eiman (mikael@eiman.tv)
Copyright 2001
The following rules apply to the use of this code:
* The code may be freely distributed, as long as this comment isn't removed or edited
* The code may not be used for commercial purposes without the explicit permission of the author
* If you fix anything, send a copy of the corrected code to the author!
*/
#include <InputServerDevice.h>
#include <stdio.h>
#include <InterfaceDefs.h>
#include <Messenger.h>
#include <MessageQueue.h>
int32 port_thread_func( void * _data );
This file has been truncated. show original
You need an input_server add-on to receive the data and post it to the input_server… well, at least this code works. I don’t know if it it the only way.
TmTFx
November 9, 2021, 4:48pm
5
ah ok Now I understand the steps needed to simulate a keypress
thank you
memsom
November 11, 2021, 4:34pm
6
I don’t know if there is a more modern way, but an InputServer add-on used to be the only/best way.