Disabling Keyboard

Started by Samwise, Wed 20/06/2007 13:25:21

Previous topic - Next topic

Samwise

Hi,

I'd like to disable any keyboard use ONLY in screens that the player character doesn't appear on
(rooms with "hide player character" marked on, I guess "cOser.On = false" in my case).
How do I do that and where do I place the code?

Another problem I'm having is that for some reason every function that's triggered by the keyboard F's (F5, F7, F9...) simply doesn't work.  I can only call these function from the status line.  But other functions that are triggered by the keyboard work just fine, like TAB for opening the inventory and the debug mode options.  I've checked the on_key_press section and everything appears there as it was in the beginning, including the F's scripts.

I'm not sure that it's relevant, but I'm using Starzer's Keboard Movement module.




Khris

That's very relevant; the module has its own on_key_press and probably calls ClaimEvent(), too, when certain keys are pressed.
Since the module's on_key_press is called first, the one in the global script will be ignored in that case.

To disable keyboard use, put this at the very start of the module's function:
Code: ags
  if (!player.On) return;


To reactivate the F-keys, make sure the function doesn't call ClaimEvent(); if the keycode is 359 ... 368.

Samwise

Both things seem logical, but they don't seem to actually work.

I've placed "if (!player.On) return;" (actually "on" without capital)  at the beginning of the module script, and nothing has changed.  I've tried to place it in other places on the module script but it doesn't seem to work either.

I've searched the module script and the global script for ClaimEvent ad found nothing.  Also, it looks like the module doesn't use the F's, only the keyboard arrows.

Khris

I should have checked the module first...
There's already a check for player.on in there, so the module won't interfere if the player character is hidden.
And it doesn't use ClaimEvent(); either.

Could you post your on_key_press in the global script?

And make sure that the F-keys do what they are supposed to outside AGS. My laptop at work has a Fn key, if it gets stuck, the F-keys do all kinds of laptop related things, like setting display brightness.

Samwise

Sure, here it is:

#sectionstart on_key_press  // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) {
  // called when a key is pressed. keycode holds the key's ASCII code
  if (IsGamePaused() == 1) keycode=0;  // game paused, so don't react to keypresses
  if (keycode==17)  QuitGame(1);   // Ctrl-Q
  if (keycode==363) SaveGameDialog();   // F5
  if (keycode==365) RestoreGameDialog();  // F7
  if (keycode==367) RestartGame();  // F9
  if (keycode==434) SaveScreenShot("scrnshot.bmp");  // F12
  if (keycode==9)   show_inventory_window();  // Tab, show inventory

  if (keycode==19)  Debug(0,0);  // Ctrl-S, give all inventory
  if (keycode==22)  Debug(1,0);  // Ctrl-V, version
  if (keycode==1)   Debug(2,0);  // Ctrl-A, show walkable areas
  if (keycode==24)  Debug(3,0);  // Ctrl-X, teleport to room
 
//   if (OserIsFreezed == 1) {
//     if ((keycode==371) || (keycode==372) || (keycode==373) || (keycode==375) || (keycode==376) || (keycode==377) ||(keycode==379) || (keycode==380) || (keycode==381)) {
//     return;
// }
// }
 
}






By the way, my F's seem to work fine outside AGS.

Khris

I'd put
Code: ags
  Display("keycode: %d", keycode);

at the very beginning.

What happens if you press an F-key now?

(Btw, that stuff at the end is basically the same as if (keycode>370 && keycode<382).)

Samwise

Good idea.  What I got is really bizzare:

F1 - keycode 359
F5 - " 15
F7 and F9 - Not working! (nothing happened)
F12 - " 80
TAB - "9


Samwise

Anybody knows?

The F-keys thing is not that important to me, but disabling the keyboard while the players in off (c...on = false) really is...

SMF spam blocked by CleanTalk