Press a key to swap key setting on keyboard

GPC2 script programming for Titan Two. Code examples, questions, requests.

Press a key to swap key setting on keyboard

Postby DrNefario » Tue Feb 19, 2019 6:28 pm

Hello guys,

I wonder if there is a way that I can press a key on keyboard to swap certain key mapping, or resign some keys to new bottoms, and if i release that key on keyboard, the settings will go back to normal.

I know there is a function for controller bottoms 'remapper_swap', but as far as i understand, this function only works with controller bottoms, not meant to work for keyboard keys.

I especially want to know when i already used the 'keymapping' function in the init area to remap the keyboard keys to certain controller bottoms, how can i be able to do the things i just discribed above.

Many thanks for you all. I learned so much form this great community. Specially thanks to bonefisher for your wonderful script on BF5, the player status tracking works amazing! And thank you so much for posting your source code online, I learned a lot from it.
User avatar
DrNefario
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Sun Dec 30, 2018 12:04 pm

Re: Press a key to swap key setting on keyboard

Postby Scachi » Tue Feb 19, 2019 7:00 pm

You can use a function that reads the values of A and writes them to B and vice versa.

The code below will swap the dpad directions as long as you hold down F1 key:
Code: Select all
#include <keyboard.gph>
 
#define SWAPKEY KEY_F1 // key to hold down
 
main {
  if (key_status(SWAPKEY)) swapper();
}
 
void swapper() {
  // add all swappings here
  swap(BUTTON_10,BUTTON_11);
  swap(BUTTON_12,BUTTON_13);
}
 
// don't change this one
void swap(uint8 ida, uint8 idb) {
    set_val(ida, get_actual(idb));
    set_val(idb, get_actual(ida));
}
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Press a key to swap key setting on keyboard

Postby DrNefario » Wed Feb 20, 2019 10:25 pm

Scachi wrote:You can use a function that reads the values of A and writes them to B and vice versa.

The code below will swap the dpad directions as long as you hold down F1 key:
Code: Select all
#include <keyboard.gph>
 
#define SWAPKEY KEY_F1 // key to hold down
 
main {
  if (key_status(SWAPKEY)) swapper();
}
 
void swapper() {
  // add all swappings here
  swap(BUTTON_10,BUTTON_11);
  swap(BUTTON_12,BUTTON_13);
}
 
// don't change this one
void swap(uint8 ida, uint8 idb) {
    set_val(ida, get_actual(idb));
    set_val(idb, get_actual(ida));
}



Many thanks!

Can I ask if there is a way to remap a keyboard key?
Lets just say I already map the BUTTOM_6 to KEY_C, using the following code:

Code: Select all
 
 
#include <remapper.gph>
#include <keyboard.gph>
 
init {
    const uint8 map[] = {
        KEY_C,         BUTTOM_6
    };
    keymapping(map);
}
 



and I want to switch KEY_C to BUTTOM_7 when I am pressing KEY_Q, how can I do that?
User avatar
DrNefario
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Sun Dec 30, 2018 12:04 pm

Re: Press a key to swap key setting on keyboard

Postby Sillyasskid » Wed Feb 20, 2019 10:43 pm

Code: Select all
#include <keyboard.gph>
const uint8 map[] = { KEY_C,  BUTTON_6, };
const uint8 map2[] = { KEY_C, BUTTON_7, };
init {
  keymapping(map);
}
 
main {
bool key_state;
 
  if(key_status(KEY_Q)){
    if(!key_state) key_state = 1, keymapping(map2);
  }else if(!key_status(KEY_Q)){
    if(key_state) key_state = 0, keymapping(map);
  }
}
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: Press a key to swap key setting on keyboard

Postby DrNefario » Thu Feb 21, 2019 6:35 pm

Sillyasskid wrote:
Code: Select all
#include <keyboard.gph>
const uint8 map[] = { KEY_C,  BUTTON_6, };
const uint8 map2[] = { KEY_C, BUTTON_7, };
init {
  keymapping(map);
}
 
main {
bool key_state;
 
  if(key_status(KEY_Q)){
    if(!key_state) key_state = 1, keymapping(map2);
  }else if(!key_status(KEY_Q)){
    if(key_state) key_state = 0, keymapping(map);
  }
}




Ah! Brillant! Thanks!
User avatar
DrNefario
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Sun Dec 30, 2018 12:04 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 93 guests