Jump to content

[Solved] Binding 2 keys


SpecT

Recommended Posts

Posted (edited)

Hello guys!

I'm wondering how it is possible to bind 2 keys to do one function. But to let it call the function they have to be pressed both of them. For example ctrl + p then it will call the function.

Thanks in advance!

Edited by Guest
Posted
function playerPressedKey ( button, press ) 
    if ( button == "lctrl" ) then 
        setElementData ( localPlayer, "lctrl", press and true or false ); 
    end 
    if ( button == "p" and press ) then 
        local pressed = getElementData ( localPlayer, "lctrl" ); 
        if ( pressed ) then 
            -- ctrl + p combination was pressed 
        end 
    end 
end 
addEventHandler ( "onClientKey", root, playerPressedKey ); 

Maybe it is faster way to do that, but that's only my example.

Posted (edited)
function playerPressedKey ( button, press ) 
    if ( button == "lctrl" ) then 
        setElementData ( localPlayer, "lctrl", press and true or false ); 
    end 
    if ( button == "p" and press ) then 
        local pressed = getElementData ( localPlayer, "lctrl" ); 
        if ( pressed ) then 
            -- ctrl + p combination was pressed 
        end 
    end 
end 
addEventHandler ( "onClientKey", root, playerPressedKey ); 

Maybe it is faster way to do that, but that's only my example.

Oh, thanks I just made something similar and it worked. Thanks anyway!

And I have got another question:

I searched in the wiki for a function to get players copied text (clipboard) but there is no function like this because of security reasons. So I want to make a dxEdit bar where I could paste my text ... Is there any way to make it so I will be able to paste the text I copied - just like in GUI.

Edited by Guest
Posted (edited)
  
function bind() 
    bindKey("p", "down", chatFunction) 
end 
function unbind() 
    unbindKey("p", "down", chatFunction) 
end 
bindKey ( "ctrl", "down", bind) 
bindKey ( "lshift", "up", unbind) 

Edit: oops my bad i posted it late.

Edited by Guest
Posted (edited)
CTRL + C -> guiGetText -> setElementData

CTRL + V -> getElementData -> guiSetText

Yeah, but I wanna do it in dx ... Is it possible? Tell me if it's not then I will do it with GUI ..

PS: I mean: just like setClipboard but getClipboard somehow. I want to let it take what I copied for example youtube link and paste it in the edit box (DX).

PS: I'm not using GUI's editbox.

Edited by Guest
Posted
Hello guys!

I'm wondering how it is possible to bind 2 keys to do one function. But to let it call the function they have to be pressed both of them. For example ctrl + p then it will call the function.

Thanks in advance!

about your first question it can be like this :

function example(key) 
    if (key == "p") then 
            if (getKeyState("lctrl")) then 
 -- You code here 
   end  
 end  
end  
bindKey("p", "down", example) 

About second question : Yes you can use setClipboard()

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
Hello guys!

I'm wondering how it is possible to bind 2 keys to do one function. But to let it call the function they have to be pressed both of them. For example ctrl + p then it will call the function.

Thanks in advance!

about your first question it can be like this :

function example(key) 
    if (key == "p") then 
            if (getKeyState("lctrl")) then 
 -- You code here 
   end  
 end  
end  
bindKey("p", "down", example) 

About second question : Yes you can use setClipboard()

About my first question I already made it.

And about my second question: You didn't get it right. I want when I'm in-game to get player's copied text (for example youtube link) and paste it in-game in dxEditBox. My question is: How to get player's clipboard (When you copy with ctrl + c) ?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...