Registering Windows keys => Linux and Mac

BlitzMax Forums/BlitzMax Programming/Registering Windows keys => Linux and Mac

Armitage 1982(Posted 2009) [#1]
Hi

This External code Registering system keys in Windows 32 :

rem
bbdoc:Registering keys in windows 32 (print screen -=> screenshot)
end rem
Extern "Win32"
	Function GetAsyncKeyState:Int(key:Int)
	Function RegisterHotKey:Int(hwnd:Int, ID:Int, Modifiers:Int, VK:Int)
	Function GetActiveWindow:Int()
End Extern


I plan to build my software in Linux (Ubuntu 8.10) and maybe MacOsX.

1) What would be the corresponding function on these platform ??

2) Also, would this registering functions work in Vista ?


Thanks :)


degac(Posted 2009) [#2]
1) for what I know there's nothing like the 'Windows Registry' on both Linux and mac os x...


dawlane(Posted 2009) [#3]
Linux hasn't got any thing like the "Windows Registry". All program data is usually stored in scripts.
I think you would have to look at the XServer and the Kernel and write your own ( It may get tricky as any low level access needs root privileges )
This may be of help http://www.dreamincode.net/forums/showtopic84453.htm

For Vista it could be a hit and miss affair. You will more than likely need administrator credentials or the UAC disabled. A bit of Googling around showed lots of people asking this question but with no real answers (it work for some but not for others).


Mark Tiffany(Posted 2009) [#4]
I don't think the question has anything (directly) to do with windows registry. The question is about registering a hotkey (keypresses). This might ultimately record a registry entry I guess...

If you are using maxgui, there are cross-platform means of adding hotkeys to your app, but I am pretty sure your app has to be active (in focus) for these to work. I suspect you are asking for a means of having a keypress work throughout the entire OS for all apps to do something special? If so, then no idea if it can be done, but I kind of suspect not...


Brucey(Posted 2009) [#5]
On Mac, yes there's an API for this... but many keys/combinations already have presets, so you need to be very careful not to tread on the system's toes.

You can also apply runtime/application hotkey as Mark mentions - which is the standard way of doing things.


Armitage 1982(Posted 2009) [#6]
Thanks for you advices :)

My goal was to modify the primary behaviour of touch like "Print screen" and so.
As this involve too many try and guess operations I will probably choose simplier solutions.

Building my game in Linux brings tons of weird behaviour with Box2D, Cegui and time operation.
Since that I'm not sure I'm going to put more work on porting this on multiple platform afterall.

Thanks :)


Brucey(Posted 2009) [#7]
weird behaviour? I shouldn't think so.

I've not had problems running these on Linux. (I generally test everything on all platforms)


Armitage 1982(Posted 2009) [#8]
@Brucey : Hell Yeah :)

Like KEY_TILDE (222) is touch [4] on my keyboard or Touch [1] = key UP even if key UP is working too.
But I could work around that !

Maybe it's not Modules problems but some part of my code work in this way :

Box2D : (cp is a contactPoint and contain the 2 colliding box2d Shapes, TWater is a class)
Local notSensor:Int = Not cp.shape1.IsSensor() And Not cp.shape2.IsSensor() Or TWater(obj)


In Windows IsSensor() return 0 or 1 so it's working
In Ubuntu IsSensor() return a weird number (maybe reference ?) like :

Local notSensor:Int = Not 152166521 And Not 191942812 Or TWater(obj)

And obviously this will never work :(
(I check the API : isSensor() shall return true or false)

I often use combination of boolean value in my game which is why for example my player won't jump.

Unfortunately I also get this trouble with CEGUI where the problem is critical.
Some hidden windows shown unexpectedly, checkbox combination never work, etc.

If I must change every part of my game were numeric int are return rather than boolean value (one of the worst missing feature in blitzmax imo) this will take ages !

Your advice on this is welcome :)


Armitage 1982(Posted 2009) [#9]
I try to find a specific problem with CEGUI.

Like Box2d functions or methods returning bool in C++ like :
TCERadioButton.isSelected()

return those kind of answer in Linux : 168744448


Brucey(Posted 2009) [#10]
I see the problem...

And I suppose if you do something like :

If mybutton.isSelected() = True Then

instead of

If mybutton.isSelected() Then

it would be an issue.

I've never had this problem, because I always use the second version (which reads better for me, but I realise that many people like to write lots of extra code in their programs).


Anyhoo... :-)

Try the revised Box2D module and let me know if everything still works on Windows too.


Armitage 1982(Posted 2009) [#11]
In fact I cannot always regroup those checks and I don't like many lines of enclosed "if"

Oups !
Building error here :
C:/BlitzMax/mod/bah.mod/box2d.mod/box2d.debug.win32.x86.a(box2d.bmx.debug.win32.x86.o): undefined reference to `bmx_b2bodydef_getmassdata'



Mark Tiffany(Posted 2009) [#12]
Like KEY_TILDE (222) is touch [4] on my keyboard or Touch [1] = key UP even if key UP is working too.

I think BlitzMax built in constant for KEY_TILDE and KEY_QUOTE are the wrong way around. At least, they are from my POV on my UK keyboard...although I've assumed that they are defined based on US defaults and it's just that UK keyboards in general are considered wrong (when we're clearly in the right!).


Brucey(Posted 2009) [#13]
Building error here

Oops... I'm getting lax in my old age.. Sorry about that. Fixed.


Armitage 1982(Posted 2009) [#14]
I see you just update svn ;)

I try without the missing definition and working great on Linux now ! :D
Thanks million !

Do you think it would be possible to do the same for CEGUI ? (if it's not asking too much ^^)
I'm just amaze to be able to try my stuff on Linux :p


Brucey(Posted 2009) [#15]
Do you think it would be possible to do the same for CEGUI

Yeah... I'm having to think about going through all my modules now... ho hum.

It's interesting, because under certain circumstances it doesn't care whether it says bool or int... but obviously, given that an int is 4 bytes and a bool is 1, it was always going to crop up at some point. (and at the back of my mind I had a niggly feeling about using bools)

Fun fun :-)


Armitage 1982(Posted 2009) [#16]
Yeah... I'm having to think about going through all my modules now... ho hum.


Aie !!
it may hurt...

Grunt process is really something I dislike. I'm often tempted to "find and replace" most of the problem and that's exactly there where problems begin ^^
Look like this time it's only a question of bool => int conversion but if you ever need some help somewhere...


Brucey(Posted 2009) [#17]
Look like this time it's only a question of bool => int conversion

More or less... (except for the places where that doesn't work, of course ;-)

I think that's CEGUI done... better try it out and let me know either way.