Events from other programs?

BlitzMax Forums/BlitzMax Programming/Events from other programs?

xlsior(Posted 2007) [#1]
Is it possible to read events happening to other programs from within blitz?

e.g. have a program running in the background that can see it if you press a certain keyboard combination, even when it's a different program in the foreground at that moment?


Dreamora(Posted 2007) [#2]
Yes it is, but you have to use windows api or the platform api for the platform you are targetting this app at


xlsior(Posted 2007) [#3]
Just windows...

After some more digging I did find the following:
http://64.233.169.104/search?q=cache:Wn-fR-6C5TEJ:www.dotnet2themax.com/ShowContent.aspx%3FID%3D103cca7a-0323-47eb-b210-c2bb7075ba78+api+keyboard+hotkey&hl=en&ct=clnk&cd=8&gl=us

(some VB code, which provided some pointers to the 'RegisterHotKey' API which can configure specific global shortcuts that work from within any application... Which may work for my purposes, as long as it doesn't change the application focus and leaves it with the program that had it last -- not sure about that. :-?

I tried to convert it to Blitz to test, but I am missing some things... This is what I have so far:

Import "-luser32"

Extern "Win32"
'	Function FindWindow( lpClassName$z, lpWindowName$z ) = "FindWindowA@8"
'	Function FindWindowEx( hwnd1:Int, hwnd2:Int, lpsz1$z, lpsz2$z ) = "FindWindowExA@16"
'	Function SendMessage( hwnd, msg, wparam:Byte Ptr, lparam:Byte Ptr ) = "SendMessageA@16"
'	Function GetLastError()
	Function RegisterHotkey:Int (hwnd:Int,id:Int,fsmodifiers:Int,vk:Int)
	Function UnregisterHotkey:Int (hwnd:Int,id:Int)
	Function globalAddAtom:Short (lpstring:String)="GlobalAddAtomA@4"
	Function GlobalDeleteAtom:Short (nAtom:Short)
End Extern

Const Mod_Alt=1
Const Mod_Ctrl=2
Const Mod_Shift=4
Const Mod_Win=8

Global HotKeyID:Short
Global Atomname:String="X8"
Global hwnd:Int=0

win=CreateWindow("TEST",100,100,640,480)
hwnd=QueryGadget(win,QUERY_HWND)

RegisterGlobalHotKey(Key_F6, MOD_SHIFT) 
Print hotkeyid
Delay 20000
unregisterglobalhotkey()
Print hotkeyid


Function RegisterGlobalHotkey(hotkey:String,modifiers:Int)
	HotKeyID=GlobalAddAtom(atomname)
	'Print hotkeyid
	If HotkeyID=0 Then
		Print "Unable to generate unique Hotkey ID"
	EndIf
	If RegisterHotkey(hwnd,hotkeyid,modifiers,Int(hotkey)) =0 Then
		Print "Unable to register Hotkey"
		unregisterglobalhotkey()
	End If
End Function

Function UnregisterGlobalHotkey()
	If HotkeyID<>0 Then
		UnregisterHotkey(hwnd,hotkeyid)
		GlobalDeleteAtom(hotkeyid)
		hotkeyid=0
	EndIf
End Function



...but it fails with the following errors at the moment, and I can't seem to find a way to resolve that:

J:/.bmx/Global_Hotkey.bmx.console.debug.win32.x86.o(code+0x2c4): undefined reference to `RegisterHotkey@16'
J:/.bmx/Global_Hotkey.bmx.console.debug.win32.x86.o(code+0x35b): undefined reference to `UnregisterHotkey@8'




Dreamora(Posted 2007) [#4]
Perhaps not part of the .a files in blitzmax/lib as those static winapi binds are quite outdated (not really XP)

you might want to try to replace them with the ones of the most current mingw version and see if it works.


xlsior(Posted 2007) [#5]
Perhaps not part of the .a files in blitzmax/lib as those static winapi binds are quite outdated (not really XP)

you might want to try to replace them with the ones of the most current mingw version and see if it works.


When I copy the latest mingw .a files there then a few dozen additional errors pop up (pretty much all MaxGUI related from what I can see) and the original two error messages remain as well -- so that didn't fix it.