Event handling from messages - ios6

Can we add an action to the content/smiley in messages(sms) ,which is sent from an app.
*My doubt is:*How to or from where we can handle the events/action in messages

Related

Can you check if a message is a response to a wait_for coroutine in pycord

My bot is meant to mimic social media posts within a server. It sends a certain webhook embed post every time there's a message in a particular channel (on_message).
The webhook embed post has buttons such as "share". When a user clicks that button, the bot awaits their next message in the channel to send a different type of embed post. However, because the bot is already posting off of every message event, both functions go off, sending both posts. Is there a way for the bot to detect or check for if the message sent after hitting "share" is fulfilling the "share" function's wait_for coroutine, so it knows not to double-post (i.e. not have the first event go off)? Or some other way?
I know that the easiest way to do this would be to have it as a command of some sort, but I want there to be limited chances for a user to mess up when it comes to "post"ing so that no messages in those channels are default (normal) messages, only the "platform" messages.
A snippet of my code is here: https://pastebin.com/Z8VNUHQQ
Relevant lines:
39- comment = await bot.wait_for(event='message', check=check)
90- async def on_message(message)

GetMessageW is blocking the calling thread, receiving no messages

I've been struggling with this for a day now and I can't figure out what is wrong with my code. I'm coding in Rust but this is more of a Windows' api related problem.
// first, I'm installing a keyboard hook for the current thread
let hook = SetWindowsHookExW(
WH_KEYBOARD_LL,
Some(low_level_keyboard_proc), // just forwards the call with CallNextHookEx
ptr::null_mut(),
0,
);
assert!(!hook.is_null(), "Failed to install the hook");
let mut message: MSG = mem::zeroed();
GetMessageW(&mut message, ptr::null_mut(), 0, 0);
// The GetMessageW function is known to block the calling thread until a new message is sent.
// The thing is: my `low_level_keyboard_proc` handle *does get* called, so I know events are being received.
// I don't understand why the GetMessageW function never returns even though events are being processed.
// Note that my handler does not get called when I remove the GetMessageW function.
println!("Unreachable code...");
UnhookWindowsHook(hook);
I tried to use the PeekMessageW function instead but the problem is the same: the function always return FALSE (no events received) even though the handler is getting properly called.
If I remove the SetWindowsHookExW part, GetMessageW is still blocking the thread BUT if I remove the GetMessageW part and put an infinite loop it its place, the handler does not get called anymore.
... so here is the question: why does the GetMessageW function never return? And if this behaviour is normal, how am I supposed to use the message that I provide to GetMessageW.
I'm assuming I don't understand well the relationship between GetMessageW and SetWindowsHookExW.
EDIT: I understand that I can't catch the messages sent to the keyboard hook I created. Now, what would the "right" way to retrieve keyboard messages look like? Because it would be real handy to be able to get those messages directly from the message loop instead of having to send them back from the callback function to my main code using static structures.
I'm trying to create an event loop that can be used regardless of a context or the focus of a window. The idea is retrieving those messages directly from a message loop and dispatch them using a user-defined custom handler that can be used through safe rust code.
There are no window messages or thread messages being posted to the message queue of the thread that is installing the keyboard hook, so there are no messages for GetMessageW() to return TO YOU.
However, SetWindowsHookEx() uses its own messages internally when a low-level keyboard hook crosses thread/process boundaries. That is why you don't need to implement your hook in a DLL when hooking other applications. When a keyboard action occurs, a private message is sent TO THE SYSTEM targeting the thread that installed the hook.
That is why the installing thread needs a message loop. The simple act of performing message retrieval in your code is enough to get those internal messages dispatched properly, which is why your callback function is being called. You just won't see those private messages, which is why GetMessageW() blocks your code.
The same thing happens when you SendMessage() to a window across thread boundaries. The receiving thread needs a message loop in order for the message to be dispatched to the target window, even though the message doesn't go through the receiving thread's message queue. This is described in the SendMessage() documentation:
If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code.
So, what happens with SetWindowsHookEx() is that it creates a hidden window for itself to receive its private messages, sent via SendMessage(), when keyboard activity is detected in a different thread/process and needs to be marshaled back to your installing thread. This is described in the LowLevelKeyboardProc documentation:
This hook is called in the context of the thread that installed it. The call is made by sending a message to the thread that installed the hook. Therefore, the thread that installed the hook must have a message loop.

Service Broker External Activator doesn't deal with all messages in queue

I have setup external activator, which executes a simple application (as a startup) and all it does is run the following sql statement
WAITFOR(receive top(1) * from [dbo].[DBTriggersQueue]), TIMEOUT 5000;
I have a update trigger on a table, which adds messages to the queue.
My problem is if i run several update scripts(4 updates one after another) it adds the messages to the queue and my SBEA receives the event notification, however it only receives 1-2 event notifications (according to the EATrace Log) and therefore only 2 messages get dealt with by my simple app.
Does anyone know what could be causing the notifications from being sent or received by the SBEA after the initial 1/2?
It seems like something to do with time, because if I run each of my update scripts with few second delay then the event notification gets sent per update and messages dealt with.
Activation is not a per-message trigger. When you're activated you're supposed to RECEIVE all messages. Once activated keep issuing RECEIVE statements and process the messages until RECEIVE returns an empty result set. Read more details at Understanding When Activation Occurs.

I dont get responses when sending messages using PushSharp

I send push notifications using PushSharp.
I call the method StopAllServices of PushService object to let it send the messages.
I assume that after PushService.StopAllServices finishes , I got the responses for all the Notification objecs.
Afterwards I kill the thread in which the PushService object is instanciated.
PushService = New PushService()
...
...
...
PushService.StopAllServices(True)
...
'the thread dies here
I noticed that sometimes I dont get responses in the callback functions.
Can it be that the method StopAllServices doesnt wait for all responses (from APNS/GCM) ?
I need to recieve responses for all Notification objects. How to achive that ?
I'll be glad for sugestions
From the Apple push Service (APNS) you won't get response for all the successfully delivered notifications and that is "by design".
Redth (the author of pushSharp) posted a detailed explanation of this : http://redth.info/the-problem-with-apples-push-notification-ser/
So you'll barely never get one response-per-notification-sent anyway, not useful to wait for all answers to stop the service.
And keep in mind that delivering the notification to the provider (android/apple/microsoft) doesn't guarantee you the effective device delivery of the notification anyway...

Determine priority of a window message

Is there any way to programmatically check the priority of a window messages in its message queue?
For example: Some of window messages, WM_PAINT and WM_TIMER are known have the lowest priority and be placed after messages with highest priority.
I'm looking for something by which you can confirm that which one of two messages will have the lowest or highest priority or which message will be sent first or last?
That's just not how it works, Windows messages don't have a priority attached. It is mostly determined by how the message is generated. A message loop dispatches messages in this order:
first any messages generated with SendMessage() are dispatched in the order in which the calls were made
next, any messages generated with PostMessage() and stored in the message queue, in queue order
next, any messages that are synthesized from the window state. WM_TIMER, WM_PAINT and WM_MOUSEMOVE fit this category.
The 'synthesized from the window state' clause is what makes WM_PAINT and WM_TIMER appear to have a low priority. And why moving the mouse rapidly doesn't flood the message queue with mouse messages. That is however not exclusive, you can for example call UpdateWindow() to force a WM_PAINT message to be sent, making it being dispatched with a 'high priority'.
The order is defined in GetMessage / PeekMessage documentation:
If no filter is specified, messages are processed in the following
order:
Sent messages
Posted messages
Input (hardware) messages and system internal events
Sent messages (again)
WM_PAINT messages
WM_TIMER messages

Resources