MaxproGlitcher

Keyboard .lua

Mar 8th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.81 KB | None | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local GuiService = game:GetService("GuiService")
  3. local VirtualInputManager = game:GetService("VirtualInputManager")
  4.  
  5. local function getGuiParent()
  6. if syn and syn.protect_gui then
  7. local protectedGui = Instance.new("ScreenGui")
  8. syn.protect_gui(protectedGui)
  9. protectedGui.Parent = game:GetService("CoreGui")
  10. return protectedGui
  11. elseif gethui then
  12. return gethui()
  13. else
  14. return game:GetService("CoreGui")
  15. end
  16. end
  17.  
  18. local KeyboardGui = Instance.new("ScreenGui")
  19. KeyboardGui.Name = "VirtualKeyboard"
  20. KeyboardGui.ResetOnSpawn = false
  21. KeyboardGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  22. KeyboardGui.Parent = getGuiParent()
  23.  
  24. local MainFrame = Instance.new("Frame")
  25. MainFrame.Name = "MainFrame"
  26. MainFrame.Size = UDim2.new(0, 650, 0, 250)
  27. MainFrame.Position = UDim2.new(0.5, -325, 0.8, -125)
  28. MainFrame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  29. MainFrame.BorderSizePixel = 0
  30. MainFrame.Parent = KeyboardGui
  31.  
  32. local UICorner = Instance.new("UICorner")
  33. UICorner.CornerRadius = UDim.new(0, 10)
  34. UICorner.Parent = MainFrame
  35.  
  36. local TitleBar = Instance.new("Frame")
  37. TitleBar.Name = "TitleBar"
  38. TitleBar.Size = UDim2.new(1, 0, 0, 30)
  39. TitleBar.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
  40. TitleBar.BorderSizePixel = 0
  41. TitleBar.Parent = MainFrame
  42.  
  43. local TitleCorner = Instance.new("UICorner")
  44. TitleCorner.CornerRadius = UDim.new(0, 10)
  45. TitleCorner.Parent = TitleBar
  46.  
  47. local TitleLabel = Instance.new("TextLabel")
  48. TitleLabel.Name = "Title"
  49. TitleLabel.Size = UDim2.new(1, -60, 1, 0)
  50. TitleLabel.Position = UDim2.new(0, 10, 0, 0)
  51. TitleLabel.BackgroundTransparency = 1
  52. TitleLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  53. TitleLabel.TextSize = 16
  54. TitleLabel.Font = Enum.Font.SourceSansBold
  55. TitleLabel.Text = "Virtual Keyboard"
  56. TitleLabel.TextXAlignment = Enum.TextXAlignment.Left
  57. TitleLabel.Parent = TitleBar
  58.  
  59. local CloseButton = Instance.new("TextButton")
  60. CloseButton.Name = "CloseButton"
  61. CloseButton.Size = UDim2.new(0, 40, 0, 25)
  62. CloseButton.Position = UDim2.new(1, -45, 0, 2.5)
  63. CloseButton.BackgroundColor3 = Color3.fromRGB(200, 60, 60)
  64. CloseButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  65. CloseButton.Text = "X"
  66. CloseButton.TextSize = 16
  67. CloseButton.Font = Enum.Font.SourceSansBold
  68. CloseButton.Parent = TitleBar
  69.  
  70. local CloseCorner = Instance.new("UICorner")
  71. CloseCorner.CornerRadius = UDim.new(0, 5)
  72. CloseCorner.Parent = CloseButton
  73.  
  74. local KeysContainer = Instance.new("Frame")
  75. KeysContainer.Name = "KeysContainer"
  76. KeysContainer.Size = UDim2.new(1, -20, 1, -40)
  77. KeysContainer.Position = UDim2.new(0, 10, 0, 35)
  78. KeysContainer.BackgroundTransparency = 1
  79. KeysContainer.Parent = MainFrame
  80.  
  81. local ToggleButton = Instance.new("TextButton")
  82. ToggleButton.Name = "KeyboardToggle"
  83. ToggleButton.Size = UDim2.new(0, 50, 0, 50)
  84. ToggleButton.Position = UDim2.new(0, 20, 0.5, -25)
  85. ToggleButton.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
  86. ToggleButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  87. ToggleButton.Text = "⌨️"
  88. ToggleButton.TextSize = 20
  89. ToggleButton.Font = Enum.Font.SourceSansBold
  90. ToggleButton.Parent = KeyboardGui
  91.  
  92. local ToggleCorner = Instance.new("UICorner")
  93. ToggleCorner.CornerRadius = UDim.new(0, 10)
  94. ToggleCorner.Parent = ToggleButton
  95.  
  96. local keyboardLayout = {
  97. {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "Backspace"},
  98. {"Tab", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "\\"},
  99. {"Caps", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "Enter"},
  100. {"Shift", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "Shift"},
  101. {"Ctrl", "Win", "Alt", "Space", "Alt", "Fn", "Ctrl"}
  102. }
  103.  
  104. local keyToEnum = {
  105. ["1"] = Enum.KeyCode.One,
  106. ["2"] = Enum.KeyCode.Two,
  107. ["3"] = Enum.KeyCode.Three,
  108. ["4"] = Enum.KeyCode.Four,
  109. ["5"] = Enum.KeyCode.Five,
  110. ["6"] = Enum.KeyCode.Six,
  111. ["7"] = Enum.KeyCode.Seven,
  112. ["8"] = Enum.KeyCode.Eight,
  113. ["9"] = Enum.KeyCode.Nine,
  114. ["0"] = Enum.KeyCode.Zero,
  115. ["-"] = Enum.KeyCode.Minus,
  116. ["="] = Enum.KeyCode.Equals,
  117. ["Backspace"] = Enum.KeyCode.Backspace,
  118. ["Tab"] = Enum.KeyCode.Tab,
  119. ["q"] = Enum.KeyCode.Q,
  120. ["w"] = Enum.KeyCode.W,
  121. ["e"] = Enum.KeyCode.E,
  122. ["r"] = Enum.KeyCode.R,
  123. ["t"] = Enum.KeyCode.T,
  124. ["y"] = Enum.KeyCode.Y,
  125. ["u"] = Enum.KeyCode.U,
  126. ["i"] = Enum.KeyCode.I,
  127. ["o"] = Enum.KeyCode.O,
  128. ["p"] = Enum.KeyCode.P,
  129. ["["] = Enum.KeyCode.LeftBracket,
  130. ["]"] = Enum.KeyCode.RightBracket,
  131. ["\\"] = Enum.KeyCode.BackSlash,
  132. ["Caps"] = Enum.KeyCode.CapsLock,
  133. ["a"] = Enum.KeyCode.A,
  134. ["s"] = Enum.KeyCode.S,
  135. ["d"] = Enum.KeyCode.D,
  136. ["f"] = Enum.KeyCode.F,
  137. ["g"] = Enum.KeyCode.G,
  138. ["h"] = Enum.KeyCode.H,
  139. ["j"] = Enum.KeyCode.J,
  140. ["k"] = Enum.KeyCode.K,
  141. ["l"] = Enum.KeyCode.L,
  142. [";"] = Enum.KeyCode.Semicolon,
  143. ["'"] = Enum.KeyCode.Quote,
  144. ["Enter"] = Enum.KeyCode.Return,
  145. ["Shift"] = Enum.KeyCode.LeftShift,
  146. ["z"] = Enum.KeyCode.Z,
  147. ["x"] = Enum.KeyCode.X,
  148. ["c"] = Enum.KeyCode.C,
  149. ["v"]= Enum.KeyCode.V,
  150. ["b"] = Enum.KeyCode.B,
  151. ["n"] = Enum.KeyCode.N,
  152. ["m"] = Enum.KeyCode.M,
  153. [","] = Enum.KeyCode.Comma,
  154. ["."] = Enum.KeyCode.Period,
  155. ["/"] = Enum.KeyCode.Slash,
  156. ["Ctrl"] = Enum.KeyCode.LeftControl,
  157. ["Win"] = Enum.KeyCode.LeftMeta,
  158. ["Alt"] = Enum.KeyCode.LeftAlt,
  159. ["Space"] = Enum.KeyCode.Space,
  160. ["Fn"] = Enum.KeyCode.F1
  161. }
  162.  
  163. local specialKeySizes = {
  164. ["Backspace"] = 2,
  165. ["Tab"] = 1.5,
  166. ["Caps"] = 1.75,
  167. ["Enter"] = 1.75,
  168. ["Shift"]= 2.25,
  169. ["Ctrl"] = 1.5,
  170. ["Win"] = 1.25,
  171. ["Alt"] = 1.25,
  172. ["Space"] = 6,
  173. ["Fn"] = 1.25
  174. }
  175.  
  176. local function createKey(text, row, col, width)
  177. local key = Instance.new("TextButton")
  178. key.Name = "Key_" .. text
  179. key.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
  180. key.BorderSizePixel = 0
  181. key.TextColor3 = Color3.fromRGB(255, 255, 255)
  182. key.Text = text
  183. key.TextSize = 16
  184. key.Font = Enum.Font.SourceSans
  185. key.AutoButtonColor = true
  186.  
  187. local keyCorner = Instance.new("UICorner")
  188. keyCorner.CornerRadius = UDim.new(0, 5)
  189. keyCorner.Parent = key
  190.  
  191. local isHolding = false
  192. local keyCode = keyToEnum[text]
  193.  
  194. key.MouseButton1Down:Connect(function()
  195. key.BackgroundColor3 = Color3.fromRGB(100, 100, 100)
  196. isHolding = true
  197.  
  198. if keyCode then
  199. VirtualInputManager:SendKeyEvent(true, keyCode, false, game)
  200. end
  201. end)
  202.  
  203. key.MouseButton1Up:Connect(function()
  204. key.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
  205. isHolding = false
  206.  
  207. if keyCode then
  208. VirtualInputManager:SendKeyEvent(false, keyCode, false, game)
  209. end
  210. end)
  211.  
  212. key.MouseLeave:Connect(function()
  213. if isHolding and keyCode then
  214. VirtualInputManager:SendKeyEvent(false, keyCode, false, game)
  215. isHolding = false
  216. key.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
  217. end
  218. end)
  219.  
  220. return key
  221. end
  222.  
  223. local rowHeight = 1 / #keyboardLayout
  224. local currentY = 0
  225.  
  226. for rowIndex, row in ipairs(keyboardLayout) do
  227. local totalWidth = 0
  228. for _, key in ipairs(row) do
  229. totalWidth = totalWidth + (specialKeySizes[key] or 1)
  230. end
  231.  
  232. local currentX = 0
  233. for keyIndex, keyText in ipairs(row) do
  234. local keyWidth = specialKeySizes[keyText] or 1
  235. local relativeWidth = keyWidth / totalWidth
  236.  
  237. local key = createKey(keyText, rowIndex, keyIndex, keyWidth)
  238. key.Size = UDim2.new(relativeWidth, -2, rowHeight, -2)
  239. key.Position = UDim2.new(currentX, 1, currentY, 1)
  240. key.Parent = KeysContainer
  241.  
  242. currentX = currentX + relativeWidth
  243. end
  244.  
  245. currentY = currentY + rowHeight
  246. end
  247.  
  248. local function makeDraggable(frame, handle)
  249. local isDragging = false
  250. local dragInput
  251. local dragStart
  252. local startPos
  253.  
  254. handle.InputBegan:Connect(function(input)
  255. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  256. isDragging = true
  257. dragStart = input.Position
  258. startPos = frame.Position
  259.  
  260. input.Changed:Connect(function()
  261. if input.UserInputState == Enum.UserInputState.End then
  262. isDragging = false
  263. end
  264. end)
  265. end
  266. end)
  267.  
  268. handle.InputChanged:Connect(function(input)
  269. if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  270. dragInput = input
  271. end
  272. end)
  273.  
  274. UserInputService.InputChanged:Connect(function(input)
  275. if input == dragInput and isDragging then
  276. local delta = input.Position - dragStart
  277. frame.Position = UDim2.new(
  278. startPos.X.Scale,
  279. startPos.X.Offset + delta.X,
  280. startPos.Y.Scale,
  281. startPos.Y.Offset + delta.Y
  282. )
  283. end
  284. end)
  285. end
  286.  
  287. makeDraggable(MainFrame, TitleBar)
  288. makeDraggable(ToggleButton, ToggleButton)
  289.  
  290. CloseButton.MouseButton1Click:Connect(function()
  291. KeyboardGui:Destroy()
  292. end)
  293.  
  294. ToggleButton.MouseButton1Click:Connect(function()
  295. MainFrame.Visible = not MainFrame.Visible
  296. ToggleButton.BackgroundColor3 = MainFrame.Visible and Color3.fromRGB(80, 180, 80) or Color3.fromRGB(60, 60, 60)
  297. end)
  298.  
  299. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  300. if not gameProcessed and input.KeyCode == Enum.KeyCode.F2 then
  301. MainFrame.Visible = not MainFrame.Visible
  302. ToggleButton.BackgroundColor3 = MainFrame.Visible and Color3.fromRGB(80, 180, 80) or Color3.fromRGB(60, 60, 60)
  303. end
  304. end)
Advertisement
Add Comment
Please, Sign In to add comment