tkstarir
Member
Hi B4X Community
i have a question about 2 Libraries: Server Websocket and NativeHook
i wanna write an overlay keyboard screen with this 2 library and everything is ok except one thing
when NH_NativeKeyPressed Call and i Got hotkey text, i dont know how can i send it to my browser in overlay.html
this is my codes:
the problem is that it when i call SendMessage method in WebSocket Server Nothing happens. mean both Log and Alert functions not call
i have a question about 2 Libraries: Server Websocket and NativeHook
i wanna write an overlay keyboard screen with this 2 library and everything is ok except one thing
when NH_NativeKeyPressed Call and i Got hotkey text, i dont know how can i send it to my browser in overlay.html
this is my codes:
Main.b4j:
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Dim MyServer As Server
Dim MyWebSocket As Overlay_WebSocket
End Sub
Sub AppStart (Args() As String)
MyServer.Initialize("MyServer")
MyServer.Port = 1111
MyServer.AddHandler("/asd", "Overlay_Handler", False)
MyServer.AddWebSocket("/asd2", "Overlay_WebSocket")
MyServer.Start
StartMessageLoop
End Sub
Sub NH_NativeKeyPressed(Hotkey As NativeKeyEvent)
MyWebSocket.Initialize
MyWebSocket.SendMessage(Hotkey.KeyText)
End Sub
Sub NH_Unregistered
End Sub
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
WebSocket Server:
Public Sub Class_Globals
Dim ws As WebSocket
End Sub
Public Sub Initialize
End Sub
Public Sub WebSocket_Connected (WebSocket As WebSocket)
ws = WebSocket
Dim NH As NativeHook
NH.Initialize("NH", Main)
NH.startNativeKeyListener
NH.enableKillCode
NH.EnableEventConsumption
Log("Connected !")
End Sub
Public Sub SendMessage(message As String)
Log(message)
If message <> "" Then
ws.Alert(message)
ws.Flush
End If
End Sub
Public Sub WebSocket_Disconnected
End Sub
overlay.html:
<script type="text/javascript">
window.onload = function(){
var socket = new WebSocket('ws://127.0.0.1:1111/asd2');
socket.onopen = function(){
socket.onmessage = function(message){
try {
var json = JSON.parse(message.data);
if(json.etype == 'alert'){
document.getElementById('show_hotkey').innerHTML = json.prop;
return true;
}else{
return false;
}
} catch(error) {
return false;
}
};
};
};
</script>
<style type="text/css">
#show_hotkey {
color: red;
font-size: 50px;
font-weight: bold;
margin: 50px;
}
</style>
<span id="show_hotkey">HotKey</span>
the problem is that it when i call SendMessage method in WebSocket Server Nothing happens. mean both Log and Alert functions not call
Last edited: